python standard lib equivalent to dateutil.parser.parse
Asked Answered
O

1

5

I'm parsing datetimestamps using python dateutil, but would like to avoid the extra dependency. So Is there a way to do the equivalent with the standard python library:

dateutil.parser.parse("2012-12-12T12:00")

Thanks a lot!

Outthink answered 10/12, 2012 at 15:13 Comment(1)
Write your own using strptime ?Bottomry
C
8

If your date strings are all in the same format, you could use strptime like this:

In [31]: import datetime as DT

In [32]: DT.datetime.strptime("2012-12-12T12:00", '%Y-%m-%dT%H:%M')
Out[32]: datetime.datetime(2012, 12, 12, 12, 0)
Commonality answered 10/12, 2012 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.