how can I convert the date format from
Current format : [day] [month] [day value] [hour]:[minute]:[second] [time zone difference] [year]
to
New format : [year]-[month value]-[day value] [hour]:[minute]:[second]
For example, a current format value:
Tue Feb 04 17:04:01 +0000 2020
should be converted to:
2020-02-04 17:04:01
in python
>Solution :
You can use parser
. Then use strftime
to format the datetime
object
from dateutil import parser
x = 'Tue Feb 04 17:04:01 +0000 2020 '
y = parser.parse(x).strftime('%Y-%m-%d %T')
>>> y
'2020-02-04 17:04:01'
Check out: