When we use the date command to change system DateTime:
date -s '2021-03-04 11:21:13'
to change system time, the system return
Thu Mar 4 11:21:13 CST 2021
It looks like the time have already changed successfully, but run the date command again and found the time still the old.
The reason is most modern Linux system has ntp running by default, we can use timedatectl command to check
root@nbear:/opt/c# timedatectl Local time: Thu 2021-03-04 09:45:24 CST Universal time: Thu 2021-03-04 01:45:24 UTC RTC time: Thu 2021-03-04 01:45:24 Time zone: Asia/Shanghai (CST, +0800) Network time on: yes NTP synchronized: no RTC in local TZ: no
As we can see, the Network time is on, so if we want to change the system time manually, we should shut down the ntp by using the following command:
timedatectl set-ntp false
Then you can change the system time.