Python Dates and Times in Python Where on Earth do Timezones Make Sense? Timezone Maker

Kevin Nguyen
Kevin Nguyen
4,422 Points

question on timezone

I cannot file what's wrong with this line of code. Thanks.

>>> import datetime
>>> pacific = datetime.timezone(datetime.timedelta(hours=-8))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
timezones.py
import datetime

moscow = datetime.timezone(datetime.timedelta(hours=4))

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Your code passes the challenge step. I'm not sure what's going on in the shell snippet you posted above that. Is there more going on?

Getting this exact same error on my macbook air...

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

In Workspaces or coding on your actual computer?

actual computer, screen shot:

http://drp.io/bl

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Ah, you're in Python 2.7 which doesn't have datetime.timezone. You'll need to use Python 3 or always use a library like pytz to handle timezones and timezone-aware datetimes.