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