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? Datetime Awareness

Adam Vasik
Adam Vasik
11,694 Points

Turning naive into aware datetime..

I tried hill_valey = naive.astimezone(pacific), it prints datetime it should print but here it throws a bummer.. I also tried hill_valey = naive.replace(tzinfo=pacific), what this does it doesn't modify naive when printed, prints "datetime - timezone'' #OUTPUT: 2015-10-21 04:29:00-08:00

aware.py
import datetime


naive = datetime.datetime(2015, 10, 21, 4, 29)
pacific = datetime.timezone(datetime.timedelta(hours=-8))
hill_valey = naive.astimezone(pacific)

2 Answers

Steven Parker
Steven Parker
210,082 Points

In addtion to the spelling of "hill_valey" instead of "hill_valley", the instructions ask for "naive with its tzinfo attribute replaced...", and the different font used for the word "replace" hints at a different operation than the one normally used for adjusting the value as you might do with a previously localized datetime:

hill_valey = naive.astimezone(pacific)       # original
hill_valley = naive.replace(tzinfo=pacific)  # corrected
Adam Vasik
Adam Vasik
11,694 Points

Using replace() works turns out I had misspelled variable.