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 trialGCPL Treehouse1
6,054 PointsTrouble 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?
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
Treehouse Moderator 68,457 PointsHey 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
6,054 PointsGCPL Treehouse1
6,054 PointsAwesome, 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?