To change the default time zone on a CentOS/Linux server, you can follow these steps:
-
Check the current time and time zone
Open a terminal or command line window and enter the following command:1
date
This command will display the current time on the server. If the time zone is incorrect, the displayed time may differ from your local time.
-
Locate the time zone file in /usr/share/zoneinfo
Execute the following command:1
ls /usr/share/zoneinfo/
This command lists all available time zone files. Choose the appropriate time zone based on your location.
For instance, if you are in China, you can enter:
1
ls /usr/share/zoneinfo/Asia/Shanghai
This command will return a file that indicates the time zone setting for Shanghai.
-
Create a symbolic link for /etc/localtime
Run the following command:1
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
If the location of your chosen time zone file is different, replace the path in this command with the corresponding time zone file path.
-
Verify that the changes have taken effect
Run the following command again:1
date
If the time displayed matches your local time zone, you have successfully changed the default time zone on the server.
Additionally, if you are running CentOS on a virtual machine, make sure that the time zone settings on both the host and the virtual machine match.