Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Dates and Times in Python 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,360 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