Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I change date stamps in python

how can I convert the date format from

Current format : [day] [month] [day value] [hour]:[minute]:[second] [time zone difference] [year]

to

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

http://strftime.net/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading