How can I parse a timezone offset with format +00 ? Python 3 or python 2
from datetime import datetime
s = '2019-04-10 21:49:41.607472+00'
# What must I replace <XX> with, to parse +00 as the timezone offset
d = datetime.strptime(s, '%Y-%m-%d %H:%M:%S.%f<XX>')
You can use dateutil's parse for that:
from dateutil.parser import parse
s = '2019-04-10 21:49:41.607472+00'
parse(s)
datetime.datetime(2019, 4, 10, 21, 49, 41, 607472, tzinfo=tzutc())
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