I want to transfer date string into python datetime format. The string is below:
Mon, 26 Dec 2011 20:42:08 +0200
Sat, 24 Dec 2011 16:28:59 +0200
Is there any faster way to transfer the string into python datetime format without using pytz API?
>>> import datetime
>>> s = "Mon, 26 Dec 2011 20:42:08 +0200"
>>> t = datetime.datetime.strptime(s, "%a, %d %b %Y %H:%M:%S %z")
>>> t
datetime.datetime(2011, 12, 26, 20, 42, 8, tzinfo=datetime.timezone(datetime.timedelta(0, 7200)))
See the docs for a complete list of datetime placeholders.
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