I'm trying to parse this datetime string, without success yet, how can I get it?
d = '2014-05-01 18:10:38-04:00'
datetime.datetime.strptime(d,'%Y-%m-%d %H:%M:%S-%Z')
ValueError: time data '2014-05-01 18:10:38-04:00' does not match format '%Y-%m-%d %H:%M:%S%Z'
Python has a built-in method to parse dates, strptime . This example takes the string “2020–01–01 14:00” and parses it to a datetime object. The documentation for strptime provides a great overview of all format-string options.
You can also use python-dateutil
module:
>>> from dateutil import parser
>>> d = '2014-05-01 18:10:38-04:00'
>>> parser.parse(d)
datetime.datetime(2014, 5, 1, 18, 10, 38, tzinfo=tzoffset(None, -14400))
Also see:
Did you try iso8601 lib? first install it: https://pypi.python.org/pypi/iso8601/
Then:
import iso8601
mydate = '2014-05-01 18:10:38-04:00'
iso8601.parse_date(mydate)
Out[3]: datetime.datetime(2014, 5, 1, 18, 10, 38, tzinfo=<FixedOffset '-04:00'>)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With