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? pytz Format

Ronnie Barua
Ronnie Barua
17,665 Points

What am I doing wrong with Starter is a naive datetime?

import datetime import pytz pacific = pytz.timezone('US/Pacific') fmt = '%m-%d %H:%M %Z%z' starter = pacific.localize(datetime.datetime(2015, 10, 21, 4, 29)) starter.strftime(fmt) starter_pacific = starter.astimezone(pacific)

pytzstring.py
import datetime
import pytz
pacific = pytz.timezone('US/Pacific')
fmt = '%m-%d %H:%M %Z%z'
starter = pacific.localize(datetime.datetime(2015, 10, 21, 4, 29))
starter.strftime(fmt)
starter_pacific = starter.astimezone(pacific)

4 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Don't change starter. Use starter and pytz to make a new datetime, named local, that is starter in the US/Pacific timezone. Since starter is naive, you can't use astimezone() on it.

Ronnie Barua
Ronnie Barua
17,665 Points

Thank you so much Kenneth.

Ronnie Barua
Ronnie Barua
17,665 Points

Thanks again. I have finally passed with your help.

Jose Luis Lopez
Jose Luis Lopez
19,179 Points

I had a really bad time with this exercise, but I finally passed it. We do not need to change any of the code that your are giving us right?. Therefore, we have to make a new variable with the name 'local' that will contain the starter code but also to make a time zone like in the video. this is a good exercise