How to Adjust Linux System to Correct Time Zone

How to Adjust Linux System to Correct Time Zone

 

If your Linux system time zone configuration is incorrect, you must manually adjust to the correct local time zone. NTP only calculates the offset between local time and UTC time in the time synchronization process, so configuring an NTP to synchronize time cannot solve the problem of incorrect time zone. Therefore, when you use foreign cloud computing service providers such as Microsoft Azure or other VPS and virtual machines, you need to pay attention to whether it is consistent with the time zone of mainland China.

 

View the current time zone in Linux

You can check the current timezone of your Linux system very easily with the following command:

date
ls -l /etc/localtime

 

How to Adjust Linux System to Correct Time Zone
How to Adjust Linux System to Correct Time Zone

 

Get time zone TZ value

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

 

1 Execute the tzselect command

How to Adjust Linux System to Correct Time Zone
How to Adjust Linux System to Correct Time Zone

2 Select your continent, country and city through the wizard, tzselect will finally output your time zone value in Posix TZ format (eg Asia/Shanghai), record this.

How to Adjust Linux System to Correct Time Zone
How to Adjust Linux System to Correct Time Zone

 

Change each user's time zone

A multi-user system for Linux users, each user can configure their own time zone, you can add a TZ environment variable for yourself:

export TZ='Asia/Shanghai'

 

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

source ~/.bashrc

 

Change Linux system time zone

To change the system-wide time zone of a Linux system, use the following command:

sudo rm -f /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

 

Note: Please replace the specific time zone in /usr/share/zoneinfo/Asia/Shanghai with the TZ value obtained by yourself.

 

Change Linux system time zone with Systemd

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. There is a system service called systemd-timedated under Systemd 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'

 

How to Adjust Linux System to Correct Time Zone
How to Adjust Linux System to Correct Time Zone

Finally, if you find that the time between Ubuntu and Windows is out of sync , you can refer to our previous article for instructions and solutions.

 

Original: https://www.sysgeek.cn/change-timezone-linux/

From: How to adjust the Linux system to the correct time zone

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326624503&siteId=291194637