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

Not getting ValueError on "naive". What's different on newer versions of python?

>>> import datetime
>>> pacific = datetime.timezone(datetime.timedelta(hours=-8))
>>> eastern = datetime.timezone(datetime.timedelta(hours=-5))
>>> naive = datetime.datetime(2019, 1, 22, 9)
>>> naive
datetime.datetime(2019, 1, 22, 9, 0)
>>> aware = datetime.datetime(2019, 1, 22, 9, tzinfo=pacific)
>>> aware
datetime.datetime(2019, 1, 22, 9, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600)))
>>> naive.astimezone(eastern)
datetime.datetime(2019, 1, 22, 7, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=68400)))

Can someone explain me what's naive tzinfo argument set when I don't pass any argument to it?

I supposed that if I don't pass any tzinfo when creating a date time object, it will be set to the timezone to the location I'm at. But I would appreciate someone more knowledgeable if I'm correct and what are the differences between newer versions of python and the one Kenneth's using.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

You are correct! The behavior of .astimezone() changed in Python 3.6:

"Changed in version 3.6: The astimezone() method can now be called on naive instances that are presumed to represent system local time."

good I thought my computer was broken

Em Noble
Em Noble
6,967 Points

thanks!! i was confused on this also