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

Adam Vasik
Adam Vasik
11,702 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
231,248 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,702 Points

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