[Linux Basics] How to change time zone

If your Linux system time zone is not configured correctly, you must manually adjust to the correct local time zone. NTP synchronizes time processing only calculates the offset between local time and UTC time. Therefore, configuring an NTP to synchronize time does not solve the problem that the time zone is incorrect. Therefore, when you use a cloud computing service provider such as Microsoft Azure or other VPS or virtual machine, you need to pay attention to whether it is consistent with the time zone of your country.

View the current time zone of Linux
You can easily view the current time zone of your Linux system using the following command:
date
ls -l /etc/localtime

Get the time zone TZ value
To change the Linux system time zone, first, get the TZ value of your local time zone. Use the tzselect command to view and select the installed time zone file.

By selecting your continent, country, and city through the wizard, tzselect will eventually output your time zone value in the Posix TZ format.

Change the time zone

You can add a TZ environment variable for yourself:

export TZ=’America/Pangnirtung’

After the execution is complete, you need to log in again to the system or refresh ~/.bashrc to take effect.

source ~/.bashrc

Change the Linux system time zone
To change the entire system-wide time zone of a Linux system, you can use the following command:
sudo rm -f /etc/localtime
sudo ln -s /usr/share/zoneinfo/America/Pangnirtung /etc/localtime
Use systemd to change the Linux system time zone
If you are using a Linux system that uses systemd, you can also use the timedatectl command to change the Linux system-wide time zone. Under Systemd, a system service called systemd-timedated is responsible for adjusting the system clock and time zone. We can configure this system service using the timedatectl command.
sudo timedatectl set-timezone ‘America/Pangnirtung’