在 CentOS 中替换(修改)系统时间,常见有 临时修改、永久修改(使用 NTP) 和 手动设置硬件时间 几种方式。下面按常见场景说明。
date 命令date -s "2026-01-21 15:30:00"
然后同步到硬件时钟:
hwclock --systohc
timedatectl set-ntp true
查看状态:
timedatectl status
如果未安装 NTP 服务:
yum install -y chrony
systemctl enable chronyd
systemctl start chronyd
timedatectl set-ntp false
timedatectl set-time "2026-01-21 15:30:00"
hwclock --systohc
查看当前时区:
timedatectl
列出时区:
timedatectl list-timezones
设置时区(例如上海):
timedatectl set-timezone Asia/Shanghai
hwclock --set --date="2026-01-21 15:30:00"
hwclock --hctosys
解决:
timedatectl set-ntp false
systemctl disable chronyd
| 场景 | 推荐方式 |
|---|---|
| 生产服务器 | NTP(chrony) |
| 测试环境 | timedatectl set-time |
| 临时调整 | date -s |
| 时区错误 | timedatectl set-timezone |
如果你能告诉我:
我可以给你 最合适的一套命令方案。