查看时间
date 命令,输出
Sun Jul 14 07:23:03 PM CST 2024
timedatectl 命令,输出
               Local time: Sun 2024-07-14 10:30:00 CSTUniversal time: Sun 2024-07-14 02:30:00 UTCRTC time: Sun 2024-07-14 02:30:00Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yesNTP service: activeRTC in local TZ: no设置时间
-  设置系统时间: sudo timedatectl set-time "2024-07-14 10:30:00"
-  设置系统日期: sudo timedatectl set-time "2024-07-14"
-  设置时区: sudo timedatectl set-timezone "Asia/Shanghai"
同步网络时间
Ubuntu默认使用 systemd-timesyncd 服务进行时间同步。确保该服务已启用并运行。
-  检查 timesyncd服务状态:sudo systemctl status systemd-timesyncd
-  启用并启动 timesyncd服务(如果未运行):sudo systemctl enable systemd-timesyncd sudo systemctl start systemd-timesyncd
-  查看时间同步状态: timedatectl status
如果您希望使用更高级的NTP配置,可以安装 ntpd 服务。
-  安装NTP: sudo apt-get update sudo apt-get install ntp
-  启动并启用NTP服务: sudo systemctl start ntp sudo systemctl enable ntp
-  检查NTP同步状态: ntpq -p输出示例: remote refid st t when poll reach delay offset jitter ============================================================================== *ntp1.example.com .GPS. 1 u 23 64 377 0.123 -0.002 0.004 +ntp2.example.com .PPS. 1 u 24 64 377 0.456 0.000 0.003