• JUPYTER
  • FAQ
  • View as Code
  • Python 3 (ipykernel) Kernel
  • View on GitHub
  • Execute on Binder
  • Download Notebook
  1. learn-python3
  2. notebooks
  3. beginner
  4. exercises

1. Playing with datetimes¶

You're given a naive datetime, see NAIVE_DT variable below. Although this variable is naive, you happen to know that the time specified by NAIVE_DT is in UTC.

Based on this information, your task is to create new datetime variables by converting NAIVE_DT to UTC and then to time in Sydney and Los Angeles. Use the following variable names: utc_dt, sydney_dt, and la_dt.

In [ ]:
import datetime as dt
from zoneinfo import ZoneInfo, available_timezones

NAIVE_DT = dt.datetime(2000, 1, 1, 10)

If you don't know the timezone name you're looking for, this may be helpful:

In [ ]:
for tz in available_timezones():
    print(tz)

Now create utc_dt, sydney_dt, and la_dt.

In [ ]:
# Your implementation here

Let's verify that the solution is correct.

In [ ]:
assert utc_dt.isoformat() == "2000-01-01T10:00:00+00:00"
assert sydney_dt.isoformat() == "2000-01-01T21:00:00+11:00"
assert la_dt.isoformat() == "2000-01-01T02:00:00-08:00"

print("All good!")

This website does not host notebooks, it only renders notebooks available on other websites.

Delivered by Fastly, Rendered by OVHcloud

nbviewer GitHub repository.

nbviewer version: 8b013f7

nbconvert version: 7.2.3

Rendered (Tue, 10 Jun 2025 07:09:23 UTC)