I have some doubts in the dateformat Tue Feb 25 2014 00:00:00 GMT+0530 (IST).
Tue Feb 25 2014 00:00:00 means GMT or ISTdatetime. DD-MM-YY,HH:MM:SS in GMT.Here is what i tried to convert into python datetime::
but i got error,when i tried with %z:
>>> time_format="%a %b %d %Y %H:%M:%S GMT%z (%Z)"
>>> v="Tue Feb 25 2014 00:00:00 GMT+0530 (IST)"
>>> mydate=datetime.strptime(v,time_format)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/_strptime.py", line 317, in _strptime
(bad_directive, format))
ValueError: 'z' is a bad directive in format '%a %b %d %Y %H:%M:%S GMT%z (%Z)'
But this works:
>>> time_format="%a %b %d %Y %H:%M:%S GMT (%Z)"
>>> v="Tue Feb 25 2014 00:00:00 GMT (IST)"
>>> datetime.strptime(v,time_format)
datetime.datetime(2014, 2, 25, 0, 0)
but still didn't understand anything about TIMEZONE.
In the system terminal
easy_install python-dateutil
In the python shell
from dateutil import parser as date_parser
print date_parser.parse("Tue Feb 25 2014 00:00:00 GMT+0530 (IST)")
Dateutil's parse can typically just parse anything you throw at it into a Python datetime.
I think the best way would be to try something like this, especially if you want to avoid using external libraries for example in Python 3.6.9 :
datetime.strptime(v,"%a %b %d %Y %H:%M:%S %Z%z (IST)")
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