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

GCPL Treehouse1
GCPL Treehouse1
6,054 Points

Trouble with pytz Format Challenge not accepting Timezone

Anyone else having trouble getting this Challenge to accept the answer. I checked my work in the workspace, and it seems correct. The code returns: 10-20 22:29 PDT-0700, but I keep getting an error that 'local' is not the right timezone. Is it a DST issue?

pytzstring.py
import datetime
import pytz

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Hey GCPL Treehouse1, you are close, just reverse the order to use the localize method of a given time zone:

This was shown at 5:25 in the previous video

local = pytz.timezone('US/Pacific').localize(starter)

Post back if you need more help. Good luck!

GCPL Treehouse1
GCPL Treehouse1
6,054 Points

Awesome, thanks! That was killing me. Trying to make sense of the output: the correct code keeps the datetime as is, but places it in Pacific Time, while my old code was taking a datetime, treating it as utc, and changing it to the associated Pacific time?