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

Ronnie Barua
Ronnie Barua
17,665 Points

Create a new variable named hill_valley where you've replaced the tzinfo of naive with the US/Pacific timezone. US/Pacif

Can't convert/replace() tz into US/Pacific

import datetime
pacific = 8
naive = datetime.datetime(2015, 10, 21, 4, 29)
hill_valley = datetime.datetime(2015, 10, 21, 4, 29 tzinfo = US/pacific)

4 Answers

I had issues with this at first too. You have to do it all manually.

pacific = 8 is not a datetime. You need to make it subtract 8 hours from the time.

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

after that you are correct with the tzinfo = part , but you need to make it equal to the variable that is =-8 hours (pacific in this case)

all in all it would look like this:

#try to solve it, if still problems I can post solution

hopefully this helps! mark it up/best answer if it does! if not let me know!

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You forgot the comma before tzinfo. If you remember, though, we used a method to replace just singular attributes before. That's probably a better idea than rewriting the whole object all over again, yeah?

Ronnie Barua
Ronnie Barua
17,665 Points

I did it. Thank you all very very much.

no problem!

please choose best answer to resolve the question. =)

Jose Luis Lopez
Jose Luis Lopez
19,179 Points

import datetime

naive = datetime.datetime(2015, 10, 21, 4, 29) pacific = datetime.timezone(datetime.timedelta(hours=-8)) hill_valley = naive.replace(some code that will replace the tzinfo attribute)

I had a hard time with this question too, but I finally got it. I don't want to post whole answer so people can work on it, but this is a lot of help I think.