Change Linux Server Time: Step-by-Step Guide

To change the time on a Linux server, you can follow these steps:

  1. Login to the server with root privileges.
  2. Execute the following command to display the current system time:
date
  1. To modify the system time, execute the following command to set the time to a specific date and time:
date -s "YYYY-MM-DD HH:MM:SS"

“YYYY-MM-DD” represents the year, month, and day, while “HH:MM:SS” represents the hour, minute, and second.

  1. To change the system time zone, run the following command:
timedatectl list-timezones

This will list the available time zones. Choose the one that suits your location and execute the following command to set the system time zone to the selected one:

timedatectl set-timezone <时区>

For example, if your time zone is Asia/Shanghai:

timedatectl set-timezone Asia/Shanghai
  1. To synchronize the system time with the hardware clock, modify the hardware clock and execute the following command.
hwclock --systohc
  1. Please re-enter the following command to confirm that the time has been successfully updated:
date

Please be aware that changing the system time can have unexpected effects on the system, so please proceed with caution. In a production environment, it is best to have the operation performed by a system administrator or professional.

bannerAds