How to adjust Linux to the correct time zone
If your Linux system has incorrect time zone configuration, you must manually adjust it to the correct local time zone. NTP only calculates the offset between the local time and UTC time. Therefore, configuring an NTP to synchronize the time does not solve the problem of incorrect time zone. Therefore, when using foreign cloud computing service providers such as Microsoft Azure or other VPS and virtual machines, you must be aware of whether the time zone is consistent with that in mainland China.
View the current Linux time zone
You can use the following command to easily view the current time zone of the Linux system:
datels -l /etc/localtime
Get the TZ value of the time zone
To change the Linux system time zone, you must first know the TZ value of your local time zone. You can use the tzselect command to view and select the installed Time Zone file.
1. Execute the tzselect command
2. Select your continent, country, and city through the Wizard. tzselect will output your time zone value in Posix TZ format (for example, Asia/Shanghai) and record it.
Change the time zone of each user
Linux users have a multi-user system, and each user can configure their own time zone. You can add a new TZ environment variable for yourself:
export TZ='Asia/Shanghai'
After the execution is complete, you need to log on to the system again or refresh ~ /. Bashrc takes effect.
source ~/.bashrc
Change Linux time zone
To change the time zone of the entire Linux system, run the following command:
sudo rm -f /etc/localtimesudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Note: Replace the actual time zone in/usr/share/zoneinfo/Asia/Shanghai with the obtained TZ value.
Use Systemd to change the Linux System Time Zone
If your Linux system uses Systemd, you can also use the timedatectl command to change the time zone of the Linux system. In Systemd, a system service named systemd-timedated is responsible for adjusting the system clock and time zone. We can use the timedatectl command to configure this system service.
sudo timedatectl set-timezone 'Asia/Shanghai'
Finally, if you find that the time between Ubuntu and Windows is not synchronized, refer to our previous articles and solutions.
This article permanently updates the link address: