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

Not sure what I have done wrong?

I have attempted to do this and looked on the forum but get an error message saying paris doesn't have the right timezone and not sure if I am understanding the question correctly and is driving me nuts.

Any assistance would be appreciated.

aware.py
import datetime

pacific = datetime.timezone(datetime.timedelta(hours=-8))

europe = datetime.timezone(datetime.timedelta(hours=1))

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

hill_valley = datetime.datetime(2015, 10, 21, 4, 29, tzinfo=pacific)

paris = hill_valley.replace()

paris.astimezone(europe)

6 Answers

Samuel Webb
Samuel Webb
25,368 Points

For starters, in your europe variable it needs to say hours=+1

Next, what you're doing with your paris variable is incorrect. You don't need the .replace() method. Basically, you should be trying to change a parameter (tzinfo) in the hill_valley variable while assigning it to a new variable. Your paris code should look like this:

paris = hill_valley.astimezone(europe)

Overall, it should look like this:

import datetime

pacific = datetime.timezone(datetime.timedelta(hours=-8))

europe = datetime.timezone(datetime.timedelta(hours=+1))

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

hill_valley = datetime.datetime(2015, 10, 21, 4, 29, tzinfo=pacific)

paris = hill_valley.astimezone(europe)

Hope this helps you out.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

1 and +1 are the same as far as Python is concerned when used as a number, so it can just be hours=1.

Thanks I didn't think I needed to use replace but after looking at the other forum answer I thought I must have missed something but that's cleared it up for me. Thanks

Samuel Webb
Samuel Webb
25,368 Points

No problem. Glad I could help.

Casey Huckel
PLUS
Casey Huckel
Courses Plus Student 4,257 Points

I've got an issue with possibly another challenge but cannot get help with that because when I click "Get Help," it doesn't load. Here's the prompt and my code:

Great, but replace just sets the timezone, it doesn't move the datetime to the new timezone. Let's move one. Make a new timezone that is UTC+01:00. Create a new variable named paris that uses your new timezone and the astimezone method to change hill_valley to the new timezone

import datetime

naive = datetime.datetime(2015, 10, 21, 4, 29) 
timezone = datetime.timedelta(hours=-8) 
hill_valley = datetime.datetime(2015, 10, 21, 4, 29, tzinfo=datetime.timezone(datetime.timedelta(hours=-8)))
timezone = datetime.timedelta(hours=1)
paris = hill_valley.astimezone(europe)

It says Task One isn't passing. Please help

Casey Huckel
PLUS
Casey Huckel
Courses Plus Student 4,257 Points

Europe isn't mentioned in the prompt. This is Datetime and Awareness challenge task 2 of 2. Probably unrelated to the discussion but like I said, I couldn't get help any other way.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I know europe isn't mentioned in the prompt, but you're using europe in your paris line so it has to exist or you're going to get a failing code challenge.

Casey Huckel
PLUS
Casey Huckel
Courses Plus Student 4,257 Points

Ok, I'm gonna start over. Where do you suggest I go from here?

import datetime

naive = datetime.datetime(2015, 10, 21, 4, 29) timezone = datetime.timedelta(hours=-8) hill_valley = datetime.datetime(2015, 10, 21, 4, 29, tzinfo=datetime.timezone(datetime.timedelta(hours=-8)))

import datetime

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

#hill_valley = naive.replace(tzinfo = pacific)

hill_valley = naive.astimezone(paris)

This works in my IDE but not in the challenge...