Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Dates and Times in Python (2014) 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.