Victory
Victory

Reputation: 131

Unable to change timezone from EST

I'm not sure what is wrong in below code. Can someone please guide.

from datetime import datetime
time = 'Sun Nov 09 19:00:00 EST 2031'
dt = datetime.strptime(time,'%a %b %d %H:%M:%S %Z %Y')
print dt

Error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/_strptime.py", line 325, in _strptime
    (data_string, format))
ValueError: time data 'Sun Nov 09 19:00:00 EST 2031' does not match format '%a %b %d %H:%M:%S %Z %Y'

Upvotes: 1

Views: 26

Answers (1)

wasmachien
wasmachien

Reputation: 1009

The only timezones that strptime recognizes are UTC, GMT and whatever is returned by time.tzname. It seems however that even when you supply one of those, the time zone information is discarded.

See https://bugs.python.org/issue22426

Upvotes: 1

Related Questions