Reputation: 31
When I run:
datetime.strptime('UTC', '%Z')
It compiles just fine, because as specified here the representation for time zone abbreviations is '%Z'
But if I run...
datetime.strptime('EST', '%Z')
I get a ValueError, 'EST' does not match the format '%Z', even though like before 'EST' is even provided as an example for %Z at the same link I provided above
What am I doing wrong?
Upvotes: 2
Views: 484
Reputation: 2109
from datetime import datetime, timedelta
from pytz import timezone
import pytz
eastern = timezone('US/Eastern')
loc_dt = eastern.localize(datetime(2002, 10, 27, 6, 0, 0))
print(loc_dt.strftime('%Z'))
For refrence Please have a look at this link (http://pytz.sourceforge.net/)!
Upvotes: 1
Reputation: 47374
If you need to work with timezones use pytz
from pytz import timezone
str(datetime.datetime.now(timezone('EST')))
Upvotes: 0