Get Time Zone of Own System in Python (3 Examples)


In this tutorial you’ll learn how to get the time zone of your system using the Python programming language.

The tutorial is structured as the table below:

Then, let’s get straight into the tutorial!


Loading the time Module

As a first step, we have to import the time module.

import time


Example 1: Getting the Time Zone Simply with tzname

The tzname function returns two strings as a tuple in which the first string is the name of the local non-DST time zone and the second string is the name of the local DST timezone.

print("Timezone: ", time.tzname)
#Time Zone:  ('CET', 'CEST')


Example 2: Getting the Time Zone with localtime

The localtime function returns the current localtime as a timetuple when it’s run without any parameters and strftime function is used to get specific fields out of timetuples and format them as desired. The combination of the two is another way of getting the time zone of the system.

print(time.strftime("Time Zone: %Z", time.localtime()))
#Time Zone: CET


Example 3: Getting the Time Zone and the Date with localtime

The combination of the localtime and strftime functions can be utilized even further to get the date, daily time and the time zone combined and it provides a very flexible way of formatting as well, an example can be seen below.

print(time.strftime("Date and Time Zone: %Y-%m-%d %H:%M:%S %Z, The time offset: %z",
#Date and Time Zone: 2022-11-11 15:52:49 CET, The time offset: +0100


Video, Further Resources & Summary

Do you need more explanations on how to get the time zone of your system? Then you should have a look at the following YouTube video of the Statistics Globe YouTube channel.


The YouTube video will be added soon.


Furthermore, you could have a look at some of the other tutorials on Statistics Globe:


This post has shown how to get the time zone of your operating system. In case you have further questions, you may leave a comment below.


Ömer Ekiz Informatics Expert

This page was created in collaboration with Ömer Ekiz. You may have a look at Ömer’s author page to read more about his academic background and the other articles he has written for Statistics Globe.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.