Timezone is a geographical time that is set for each region. It is used to compare with the standard time. When discussing timezone in Linux platforms, it is set during the installation process of the operating system. However, you can change the timezone in Linux using the command line.
Having a correct timezone setup in the system is useful for Linux systems. Because the wrong timezone may cause problems to many existing software, cron jobs, syslogs, reports & other localhost environments. The timezone is also used for logs as a timestamp.
In this tutorial, we will explain how to change or set timezone in Linux by following a simple process.
Check the Current Time Zone in Linux
Before we learn to set a new time zone in Linux, we must check the current time zone. There are different commands available to do that. In a Linux computer system, the timedatectl is a commonly used command-line utility to check the current date and time. It is useful to view and change the system’s time and date. timedatectl is available on all systemd-based Linux operating systems.
How to use timedatectl command?
To use the command, simply write timedatectl in the terminal. This command does not require any arguments or options.
It will return the output of the date and time of your system.
Local time: Wed 2022-01-26 04:50:14 PST Universal time: Wed 2022-01-26 12:50:14 UTC RTC time: Wed 2022-01-26 12:50:14 Time zone: America/Los_Angeles (PST, -0800) System clock synchronized: yes NTP servuce: active RTC in local TZ: no
Normally, the system timezone is configured with /etc/localtime file and /usr/share/zoneinfo directory. Both files are symlinked together to provide system date and time.
To check timezone using /etc/localtime symlink, you have to use ls command with -l option.
Type the following code in terminal:
ls -l /etc/localtime
The above-mentioned command will give output as below.
lrwxrwxrwx 1 root root 39 Jan 26 03:18 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC
Change the timezone in Linux
To change the timezone, you must know the long name of the region which you want to use to change the timezone. The timezone naming syntax follows the “Region/City” format.
Before, that we will know the long name of timezone using the command timedatectl with option list-timezones as below.
It will display the list of all available timezones in the “Region/City” format, have a look at the output below.
... America/Montserrat America/Nassau America/New_York America/Nipigon America/Nome America/Noronha ...
Once you finalize the timezone you want to change, run the below command as a root user or run with sudo privileges.
sudo timedatectl set-timezone <your_selected_time_zone>
For example, if you want to change the system’s timezone to America/Montserrat you would have to type the command as below.
sudo timedatectl set-timezone America/Montserrat
Once you hit ENTER it will update the timezone effective immediately.
How to verify that the timezone is updated or not?
Use the command timedatectl again, to check whether the timezone updated successfully or not.
It will return the output with an updated timezone. That’s it, you did successfully change the timezone of your Linux system.
There are different ways out there to change or set timezone in Linux systems. Another way to achieve that is by creating a symlink of /etc/localtime to /usr/share/zoneinfo directory. To make the whole process easy, you can use the sudo timedatectl set-timezone command with the region name you want to set.