Linux时间查看和设置

查看时间

date 命令,输出

Sun Jul 14 07:23:03 PM CST 2024

timedatectl 命令,输出

               Local time: Sun 2024-07-14 10:30:00 CST
           Universal time: Sun 2024-07-14 02:30:00 UTC
                 RTC time: Sun 2024-07-14 02:30:00
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

设置时间

  1. 设置系统时间:

    sudo timedatectl set-time "2024-07-14 10:30:00"
    
  2. 设置系统日期:

    sudo timedatectl set-time "2024-07-14"
    
  3. 设置时区:

    sudo timedatectl set-timezone "Asia/Shanghai"
    

同步网络时间

Ubuntu默认使用 systemd-timesyncd 服务进行时间同步。确保该服务已启用并运行。

  1. 检查 timesyncd 服务状态:

    sudo systemctl status systemd-timesyncd
    
  2. 启用并启动 timesyncd 服务(如果未运行):

    sudo systemctl enable systemd-timesyncd
    sudo systemctl start systemd-timesyncd
    
  3. 查看时间同步状态:

    timedatectl status
    

如果您希望使用更高级的NTP配置,可以安装 ntpd 服务。

  1. 安装NTP:

    sudo apt-get update
    sudo apt-get install ntp
    
  2. 启动并启用NTP服务:

    sudo systemctl start ntp
    sudo systemctl enable ntp
    
  3. 检查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
    
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值