Linux is the world’s most widely used open-source operating system (OS). Because Linux is open-source, it means that the code is free and available to the public to view/use. Android, one of the most popular platforms on the planet, is powered by Linux. As such, Linux is used across the world in every time zone.
In this article, we’ll explain how time zones work in Linux, and how to change the time zone.
A time zone is a region/area in which the same standard time is used. As trade, transport, and communication expanded, it became clear that a unified time-keeping system was needed. In 1884, GMT was born. In 1972, Coordinated Universal Time (UTC) replaced GMT as the world’s time standard. There are currently 37 different local times.
The importance of time zones in Linux
Having the correct time zone defined in your Linux data center servers is very important – and can even be the difference between your software working properly or not. If the time is not figured correctly, you may receive strange errors that are hard to identify and some apps or services may simply not work.
Checking the current time zone setting
In Linux “timedatectl” is the command-line utility that enables you to view and change the time and date in the system. This command is available on all systemd-based Linux systems. If you want to view the current time zone, you can invoke the “timedatectl” command without any arguments or options:
timedatectl Local time: Sun 2020-11-01 16:17:42 UTC Universal time: Sun 2020-11-01 16:17:42 UTC RTC time: Sun 2020-11-01 16:17:43 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
The output shown above tells you that the system’s time zone is currently set to UTC.
Another way of checking is to view the path the symlink is pointing to, using the “ls” command:
ls -l /etc/localtime lrwxrwxrwx 1 root root 27 Nov 1 06:28 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC
How are time zones configured?
The system time zone is configured by symlinking the /etc/localtime file to a binary time zone’s identifier in the /usr/share/zoneinfo directory.
Find your time zone
Prior to attempting to change the time zone, you need to find out the long name of the time zone that you want to use. You can view all the available time zones by using the “timedatectl” command or by listing the files in the /usr/share/zoneinfo directory. The naming convention for time zones usually uses a “Region/City” format such as America/New_York or America/Nassau.
Changing the Time Zone in Linux
There are two options when it comes to changing your time zone in Linux. We’ll go over each possibility below:
Change your time zone – Option 1
Once you have identified which time zone is relevant to your location, you should run the following command (as either root or sudo user):
sudo timedatectl set-timezone
So, to change the system’s time zone to America/New_York you would type:
sudo timedatectl set-timezone Europe/London
To verify the change you made, simply invoke the “timedatectl” command again:
timedatectl Local time: Sun 2020-11-01 16:19:49 GMT Universal time: Sun 2020-11-01 16:19:49 UTC RTC time: Sun 2020-11-01 16:19:50 Time zone: Europe/London (GMT, +0000) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
You have now successfully changed your system’s time zone.
Change your time zone – Option 2
If you are running an older version of Linux, there is a possibility that the “timedatectl” utility may not be available on your system.
If this is the case you can instead change the time zone by symlinking the /etc/localtime to the time zone that is in the /usr/share/zoneinfo directory.
Remove the current symlink or file:
sudo rm -rf /etc/localtime
Then you can identify the time zone that you want to use and create a symlink:
sudo ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
You can then verify it either by invoking the “date” command:
date Sun Nov 1 16:22:03 GMT 2020
The output will include the time zone as well as the date and time e.g. Tue Dec 3 14:10:54 EST 2019