Skip to main content

Working with Time Zones in Python

Hands-On Lab


Photo of

Training Architect





The due dates stored in the database are naive datetimes. That means they do not have a time zone associated with them. So while we can see a date and time, the datetime object is unaware of when that datetime is. What time zone at almost midnight are we talking about?

Standard practice is to store all due dates in UTC format, then change them to the relevant time zone as needed.

pytz is a 3rd-party application that helps with time zones, including daylight savings. From their documentation: pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference (datetime.tzinfo).

You will need basic Python programming and datetime skills for this lab:

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.