12345[root@Charramma ~]# dateTue Apr 6 17:35:18 CST 2021[root@Charramma ~]# date -RTue, 06 Apr 2021 17:35:54 +0800
12[root@Charramma ~]# hwclockTue 06 Apr 2021 05:36:45 PM CST -0.226496 seconds
timedatectl
修改年月日
123[root@Charramma ~]# timedatectl set-time 2018-08-30[root@Charramma ~]# dateThu Aug 30 00:00:01 CST 2018
timedatectl
修改时分秒
1234[root@Charramma ~]# timedatectl set-time 10:12:15[root@Charramma ~]# date dateThu Aug 30 10:12:20 CST 2018
直接使用 date -s
修改
12[root@Charramma ~]# date -s "2020-02-12 13:13:13"Wed Feb 12 13:13:13 CST 2020
使用ntp服务设置系统时间与网络时间同步
12[root@Charramma ~]# yum install ntp -y[root@Charramma ~]# ntpdate cn.pool.ntp.org
timedatectl list-timezones
列出所有时区
12[root@Charramma ~]# timedatectl list-timezones[root@Charramma ~]# timedatectl set-timezone Asia/Ho_Chi_Minh
或者直接复制时区文件
[root@Charramma ~]# cp /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
[root@Charramma ~]# hwclock --set --date "2020-02-23 12:12:13"
ntpdate
命令默认只同步系统时间,可以通过修改配置让硬件时间和系统时间一起更新
123[root@Charramma ~]# sed -i 's/SYNC_HWCLOCK=no/SYNC_HWCLOCK=yes/' /etc/sysconfig/ntpdate[root@Charramma ~]# systemctl restart ntpdate[root@Charramma ~]# ntpdate cn.pool.ntp.org
-w --systohc
[root@Charramma ~]# hwclock --systohc
或者
[root@Charramma ~]# timedatectl set-local-rtc 1
将日期写入CMOS
[root@Charramma ~]# clock -w
-s --hctosys
[root@Charramma ~]# hwclock --hctosys
Copyright © 2013-2021 8a.hk All Rights Reserved. 八艾云 版权所有 中山市八艾云计算有限公司 粤ICP备14095776号