linux
2020-10-25

一、查看系统时间

[root@viper.im ~]# date
Sun Oct 25 17:00:25 CST 2020
[root@viper.im ~]# date "+%F"
2020-10-25

按%F格式显示系统当前时间
%F 完整日期格式;same as %Y-%m-%d
%y 年(最后2位)
%Y 年
%m 月
%d 日
%H 时
%M 分
%S 秒

二、手动设置系统时间

[root@viper.im ~]# date -s "2020-10-25 19:24:00"
Sun Oct 25 19:24:00 CST 2020

三、设置ntp同步

启用并运行chronyd,未安装的要先安装。

systemctl enable chronyd --now

vim /etc/chrony.conf添加ntp server

#
server ntp.example.com iburst
#

重启chrony

systemctl restart chronyd

查看同步状态:

[root@viper.im ~]# timedatectl
      Local time: Sun 2020-10-25 20:52:19 CST
  Universal time: Sun 2020-10-25 12:52:19 UTC
        RTC time: Sun 2020-10-25 12:52:19
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes    #yes表示已同步
 RTC in local TZ: no
      DST active: n/a

或者用chronyc查看同步状态信息

chronyc sources -v
文章链接:http://www.viper.im/archives/linux-date-ntp.html
本文由viper.im 原创编译,转载请保留链接:linux时间常用操作