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

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