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

Why does my code not work on the challenge for dates and times in python task 2 of 2?

Here is the code and the task that is frustrating me beyond my desire and ability to withstand. I have tried many combinations of what I thought would work. The challenging part is for making the "paris" variable to replace the 'hill_valley' value. I get the irritating "Oops" message after making a change but "Oops" does not tell me anything. Thank you.

Bob

import datetime

naive = datetime.datetime(2015, 10, 21, 4, 2)

hill_valley = naive.replace(tzinfo = datetime.timezone(datetime.timedelta(hours=-8)))

paris = hill_valley.replace(datetime.datetime(datetime.timedelta(hours = 1)))

aware.py
import datetime

naive = datetime.datetime(2015, 10, 21, 4, 2)

hill_valley = naive.replace(tzinfo = datetime.timezone(datetime.timedelta(hours=-8)))
paris = hill_valley.replace(datetime.datetime(datetime.timedelta(hours = 1)))

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You need to move the datetime to the new timezone. You do that with .astimezone(), not by replacing the timezone. In other words, you're answering the question "If it's 4am in Hill Valley, what time is it in Paris?"

I guess that I was trying to make some things too simple and other things too difficult. I think that I was reading into the assignment on some parts and missing some of the key elements on others. It is tough trying to assimilate and use some of these methods - I am an old fart in a young buck's world.

Thanks for your help

Bob