An easy way to set or change timezone in Linux

Time zone (time zone) is a geographic region that has the same standard time. The time zone is usually set during OS installation, but it can be easily changed at your convenience.

Using the correct timezone is essential for many system-related tasks and processes. For example, we are in Indonesia and we have servers in the US for example, and we want to do cron jobs at 1am – 4am. Of course, we don’t need to make calculations to transfer from UTC to WIB.

In this tutorial, we’ll cover the steps required to set or change the timezone on Linux.

Check the current time zone

timedatectl It is a command line utility that allows you to view and change the system date and time. Command timedatectl Available on all modern Linux systems.

To see the current timezone, call the timedatectl command without any options or arguments:

                      Local time: Tue 2019-12-03 16:30:44 UTC
                  Universal time: Tue 2019-12-03 16:30:44 UTC
                        RTC time: Tue 2019-12-03 16:30:44
                       Time zone: Etc/UTC (UTC, +0000)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

As the output above shows, the system timezone is set to UTC:

System timezone is configured by communication /etc/localtime To the binary time zone identifier in the directory /usr/share/zoneinfo.

So another option to check the timezone is to check the path of the symbolic link with the ls command:

ls -l /etc/localtime
lrwxrwxrwx 1 root root 27 Dec  3 16:29 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC

Change time zone on Linux

Before changing the time zone, you must know the long name of the time zone you want to use. Typically, time zone naming conventions use the “region / city” format.

To list all available time zones, you can use the command timedatectl Or a list of files in the directory /usr/share/zoneinfo

timedatectl list-timezones

Once you have determined the exact timezone of your location, run the following command as the sudo user:

sudo timedatectl set-timezone <timezone>

For example, to change the system’s time zone to local time in Jakarta:

sudo timedatectl set-timezone Asia/Jakarta

Run the command timedatectl To check for changes:

                      Local time: Tue 2019-12-03 13:55:09 WIB
                  Universal time: Tue 2019-12-03 18:55:09 UTC
                        RTC time: Tue 2019-12-03 18:02:16
                       Time zone: Asia/Jakarta (WIB, +0700)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

This way, you have successfully changed your system’s timezone.

Change the time zone by creating a symbolic link

If you are running Linux distributions and older utilities timedatectl Not in your system. You can change the time zone by calling /etc/localtime To the time zone in the guide /usr/share/zoneinfo

Remove the current file or symbolic link:

sudo rm -rf /etc/localtime

Select the time zone you want to configure and symbolic linking:

sudo ln -s /usr/share/zoneinfo/Asia/Jakarta /etc/localtime

Check carefully by listing the files /etc/localtime Or carry out orders date :



To change the timezone on Linux, use the command sudo timedatectl set-timezone followed by the long name of the timezone you want to set.


Source link

Leave a Reply

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