Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python strptime with "+00" timezone offset format?

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>')
like image 973
James Wierzba Avatar asked Oct 28 '25 07:10

James Wierzba


1 Answers

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())

like image 99
Rajan Avatar answered Oct 31 '25 12:10

Rajan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!