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 trialGavin Crosthwaite
6,324 PointsNot 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.
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
25,370 PointsFor 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.
Gavin Crosthwaite
6,324 PointsThanks 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
25,370 PointsNo problem. Glad I could help.
Casey Huckel
Courses Plus Student 4,257 PointsI'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
Kenneth Love
Treehouse Guest TeacherWhere's europe
?
Casey Huckel
Courses Plus Student 4,257 PointsEurope 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
Treehouse Guest TeacherI 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
Courses Plus Student 4,257 PointsOk, 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)))
Nick Kolarik
3,747 Pointsimport 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...
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest Teacher1
and+1
are the same as far as Python is concerned when used as a number, so it can just behours=1
.