Python Dates and Times in Python Where on Earth do Timezones Make Sense? Datetime Awareness

Adam Vasik
Adam Vasik
6,651 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
204,010 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
6,651 Points

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