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
Lindsay Barrett
Python Web Development Techdegree Student 7,357 PointsHello, I am getting stuck on this question. Help is appreciated.
naive is a datetime with no timezone.
Create a new timezone for US/Pacific, which is 8 hours behind UTC (UTC-08:00).
Then make a new variable named hill_valley that is naive with its tzinfo attribute replaced with the US/Pacific timezone you made.
import datetime
naive = datetime.datetime(2015, 10, 21, 4, 29)
pacific= datetime.timezone(datetime.timedelta(hours=-8))
hill_valley = datetime.datetime(naive, tzinfo=pacific)
3 Answers
Steven Parker
243,215 PointsYour assignment of the "pacific" timezone looks good! But you'll need a different syntax to make use of it.
Hint: the "astimezone" method can be used to convert a datetime to a different timezone.
Lindsay Barrett
Python Web Development Techdegree Student 7,357 PointsTrying this but still getting an error.
import datetime
naive = datetime.datetime(2015, 10, 21, 4, 29)
pacific= datetime.timezone(datetime.timedelta(hours=-8))
hill_valley = naive.astimezone(tzinfo=pacific)
Steven Parker
243,215 PointsAccording to the Python documentation page, the name of the argument to "astimezone" is not "tzinfo" but just "tz".
But since it only takes one argument, you don't really need to name it.
Lindsay Barrett
Python Web Development Techdegree Student 7,357 PointsVery good, that worked!
naive = datetime.datetime(2015, 10, 21, 4, 29)
pacific= datetime.timezone(datetime.timedelta(hours=-8))
hill_valley = naive.astimezone(tz=pacific)
Steven Parker
243,215 PointsSteven Parker
243,215 PointsPlease provide a link to the course page for replicating the issue.