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? Introduction to Timezones

I am following along in this video, but am not getting the Value Error at about 02:35

C:\Users\andrew.mlamba>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> eat = datetime.timezone(datetime.timedelta(hours=+3))
>>> cat = datetime.timezone(datetime.timedelta(hours=+2))
>>> eat
datetime.timezone(datetime.timedelta(0, 10800))
>>> cat
datetime.timezone(datetime.timedelta(0, 7200))
>>> naive = datetime.datetime(2016, 1, 18, 0)
>>> naive
datetime.datetime(2016, 1, 18, 0, 0)
>>> naive.astimezone(eat)
datetime.datetime(2016, 1, 18, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(0, 10800)))
>>>

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Andrew

import datetime

eastern = datetime.timezone(datetime.timedelta(hours=-5))
naive = datetime.datetime(2016, 1, 18, 0)
print(naive.astimezone(eastern))  # 2016-01-17 14:00:00+03:00

I found I had this same issue when using Python 3.6, so I just went back to 3.5.2