2

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?

1
  • 1
    Are you using Python 3.5 or an earlier version? strptime has changed once or twice, it started out nearly useless for dealing with timezones and I don't think it's improved much. Commented Nov 22, 2016 at 6:19

2 Answers 2

1
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/)!

Sign up to request clarification or add additional context in comments.

Comments

0

If you need to work with timezones use pytz

from pytz import timezone str(datetime.datetime.now(timezone('EST'))) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.