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

Courses Plus Student 2,434 Points

timezone on starter variable

As my understanding, starter variable is assigned with the time which has a zone info associated [ UTC ] with it and localized.

All we need to do is convert it to UTC timezone using astimezone() method and convert it to any time zone.

Can you please confirm my understanding.

import datetime

import pytz

starter = pytz.utc.localize(datetime.datetime(2015, 10, 21, 23, 29))

2 Answers

hie Sudharsan. the first step is to create the function as the question says. inside the function you then use your pytz.timezone and astimezone to change starter to that timezone, like so

def to_timezone(tz):

starter_new = starter.astimezone(pytz.timezone(tz))

return starter_new

thank you so much!