1. Overview
A timezone is a geographic region that has a similar standard time to other regions. The system time is set by default on most Linux distros during the installation.
Having the correct timezone is essential for many system-related tasks and processes. Examples include cron jobs that use timezone and timestamps for system logs or changing the timezone in case we’ve moved to a different region.
In this tutorial, we’ll explore the different methods to change the timezone on Linux-based systems.
2. Using timedatectl
Before we can proceed with changing the current system timezone, we need to find the name of the timezone we want to use. The timezone name follows a Region/City format.
Let’s use the timedatectl command to view all available timezones:
$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
.......truncated.......
Alternatively, we can also list all the files in the /usr/share/zoneinfo directory:
$ ls /usr/share/zoneinfo
Africa Cuba GMT+0 Japan NZ-CHAT SystemV
America EET GMT-0 Kwajalein Pacific Turkey
Antarctica Egypt GMT0 leapseconds Poland tzdata.zi
.........truncated........
Once we identify the correct timezone name, let’s run the timedatectl command as a root user to change our current timezone:
$ sudo timedatectl set-timezone Europe/Brussels
We’re using the set-timezone option to change our system’s current timezone to Europe/Brussels.
Let’s use the timedatectl command to confirm the timezone change:
$ timedatectl
Local time: Kam 2022-07-28 16:17:18 CEST
Universal time: Kam 2022-07-28 14:17:18 UTC
RTC time: Kam 2022-07-28 14:17:18
Time zone: Europe/Brussels (CEST, +0200)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
3. Using a Symlink
We can also change the timezone by symlinking the /etc/localtime directory to a timezone listed in the /usr/share/zoneinfo directory. This method can be useful for legacy Linux distros that don’t have the timedatectl command available.
Let’s start by removing the current symlink:
$ sudo rm -rf /etc/localtime
Then we can identify a timezone to use and create a symlink to the timezone we select:
$ sudo ln -s /usr/share/zoneinfo/Europe/Brussels /etc/localtime
We’re using the ln command to create a symlink to the Europe/Brussels timezone.
To verify the change, we can use the date command:
$ date
Kamiisa, Adooleessa 28, 5:14:54 WB CEST 2022
Alternatively, we can also list out the /etc/localtime directory:
$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 35 Ado 28 16:14 /etc/localtime -> /usr/share/zoneinfo/Europe/Brussels
4. Using the Timezone Selection Menu
The tzselect Linux utility asks users for information about their current location or a specific location and outputs the resulting timezone description to stdout. We can use the output as a value for the $TZ environment variable.
Let’s use the tzselect command to output the name and description of a timezone:
$ tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa
2) Americas
3) Antarctica
4) Asia
5) Atlantic Ocean
6) Australia
7) Europe
8) Indian Ocean
9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the timezone using the Posix TZ format.
We’ll get a prompt to select a continent, then a country, or specify coordinates of the location.
Once we make a selection we should expect this output:
...truncated...
You can make this change permanent for yourself by appending the line
TZ='Europe/London'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Europe/London
Next, we need to set the generated timezone name with the TZ environment variable:
$ export TZ="Europe/London"
This will change the current system’s timezone to Europe/London. However, this is only a temporary change, and we need to copy and paste the command above to the .bashrc or .zshrc files.
5. Through GUI
We can also change the current system timezone using the GUI of our Linux-based system.
Let’s search for “Settings“ in the Application menu:
Alternatively, we can also right-click on the desktop and then select settings in the selection menu:
After clicking on “Settings,”, the Settings window will appear and we can click the “Date & Time” option on the navigation menu:
The time zone automatically changes whenever we have an internet connection. However, we can modify it by clicking the “Time Zone” option:
We’ll get a pop-up with the world map. We can search the current location in the search bar or click on the map to set a specific time zone.
After making a selection of a specific timezone, we can verify the change using the timedatectl command:
$ timedatectl
Local time: San 2022-07-30 18:37:48 EDT
Universal time: San 2022-07-30 22:37:48 UTC
RTC time: San 2022-07-30 22:37:48
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
6. Conclusion
In this article, we’ve explored the different methods available for changing the timezone on Linux-based systems.
Using the timedatectl command is the most recommended method for changing the current timezone. However, if we don’t have the timedatectl command available on our current system, we can create a symlink or change it through the GUI.