When a CentOS host shows the wrong time, first determine whether the timezone is wrong or the system clock is not synchronized. timedatectl reports the clock, timezone, and network synchronization status; on a host using chrony, chronyc checks its NTP sources and offset. The steps below apply to systemd-based CentOS systems and require root or sudo privileges.
Separate the system clock from the timezone
NTP synchronization corrects the system clock. A timezone controls how the same instant is displayed as a local date and time. Changing the timezone to Asia/Shanghai does not correct the clock or replace NTP synchronization.
Run timedatectl status and inspect Time zone, System clock synchronized, and NTP service. The official systemd manual documents these query and configuration commands. If the displayed time differs by a fixed number of hours, check the timezone first. If the timezone is correct but the clock keeps drifting, investigate the synchronization service and its upstream source.
Set the timezone and enable synchronization
Set the Shanghai timezone and enable the network time service available to systemd:
timedatectl list-timezones | grep -Fx Asia/Shanghai
sudo timedatectl set-timezone Asia/Shanghai
sudo timedatectl set-ntp true
timedatectl status
date
The first command should print Asia/Shanghai; if it prints nothing, confirm that timezone data is installed. timedatectl status should report Asia/Shanghai; where synchronization fields are available, inspect System clock synchronized and NTP service. Use date to confirm the local display changed. set-ntp true enables an available time service; it does not guarantee that the service is chrony.
To use chrony explicitly, choose the package-manager command for the installed release, then start the daemon:
# CentOS Linux 7
sudo yum install chrony
# CentOS Stream 8/9 and other releases using dnf
sudo dnf install chrony
sudo systemctl enable --now chronyd
systemctl is-active chronyd
chronyc sources -v
chronyc tracking
Do not run both package-manager commands; choose the one for the host. systemctl is-active should return active. In chronyc sources -v, * marks the currently selected source; chronyc tracking reports the reference source, synchronization offset, and leap status. If no source is usable, check the server or pool entries in /etc/chrony.conf and confirm that the selected NTP service is reachable. See the chronyc manual for command fields.
For ongoing synchronization, keep chronyd running rather than scheduling a one-time ntpdate command at each boot. If the host uses another NTP service, enable and configure that service as documented, and avoid running conflicting time daemons.
Set the clock manually only for a temporary case
Manual adjustment is for maintenance situations where the correct time is known but NTP is temporarily unavailable. If network synchronization is enabled, turn it off first. Replace the sample date and time with the actual value, then restore synchronization:
sudo timedatectl set-ntp false
sudo timedatectl set-time "2026-11-28 09:00:00"
sudo timedatectl set-ntp true
timedatectl status
Afterward, check the displayed time and confirm that synchronization is enabled again. The timestamp above illustrates the required format; it is not a value to use as-is. Changing the system clock can affect log ordering, scheduled jobs, and applications that validate time. On production hosts, prefer restoring the NTP source instead of making an uncoordinated large forward or backward adjustment.
Limitations
timedatectl set-ntp trueenables an available synchronization service. If none is installed or supported, install and configure chrony or another time daemon.- NTP requires a reachable time source. Cloud network rules, firewalls, or upstream restrictions may block synchronization; select a source allowed by the host's network policy.
- CentOS Linux 7 and CentOS Linux 8 have reached end of life. CentOS Stream and CentOS Linux are different release branches; see the CentOS lifecycle notice.
- Virtual machines and containers depend on their host and runtime boundaries. Changing a container's timezone affects its local display, not the host clock.
FAQ
Does timedatectl set-timezone Asia/Shanghai synchronize the clock with NTP?
No. The command changes local-time formatting, not the system clock. Clock correction requires an available NTP service. Check timedatectl status, then inspect chronyc sources -v and chronyc tracking when the host uses chrony. Confirm that a source is usable and the daemon is synchronized before treating the displayed time as corrected. Container time also depends on the host. If sync is inactive, check whether the NTP source is reachable over UDP port 123.
How can I verify the timezone if date shows CST?
Use the full timezone name, not CST alone, because that abbreviation can refer to different regions. Run timedatectl status and confirm that the Time zone field says Asia/Shanghai; date +%z shows the numeric offset but does not identify the timezone rule by itself. The full IANA identifier is the reliable check.
Why is the time still wrong after starting chronyd?
It may lack a usable time source. Check chronyc sources -v for a selected source and chronyc tracking for the reference and synchronization state. If sources are unavailable, review the configuration, DNS resolution, and network policy for access to the configured NTP service. Avoid repeatedly changing the clock by hand without confirming the source.
Community & Resources
- NTP Pool Project: regional NTP pool information and usage guidance; follow the policy for your network.
- Cloud Servers
- Server Operations Tips
- Linux Server Basics
Original source: cnblogs.com (CQZHUOMI) ↗