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

SUDHARSAN CHAKRAVARTHI
PLUS
SUDHARSAN CHAKRAVARTHI
Courses Plus Student 2,434 Points

Dates and times objective

In the function , after the below line utc_datezone = starter.astimezone(pytz.utc) , i don't know how to proceed.

timezone.py
import datetime

import pytz

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

def to_timezone(str_zone):
  utc_datezone = starter.astimezone(pytz.utc)
  return utc_datezone.astimezone(str_zone)

1 Answer

Keerthi Suria Kumar Arumugam
Keerthi Suria Kumar Arumugam
4,585 Points

"str_zone" in your code is a string like "US/Pacific" or "Pacific/Auckland". You need to convert that to a timezone using pytz.timezone() method. Please refer the code below.

Also please try to include your task objective in future questions. It saves us a lot of time.

import datetime

import pytz

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

def to_timezone(str_zone):
    return starter.astimezone(pytz.timezone(str_zone))