CentOS 7修改系统时间及硬件时间


转载于:https://www.cnblogs.com/LouisZJ/p/8554991.html

[root@nginx ~]# timedatectl --help
timedatectl [OPTIONS...] COMMAND ... Query or change system time and date settings. -h --help Show this help message --version Show package version --no-pager Do not pipe output into a pager --no-ask-password Do not prompt for password -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container --adjust-system-clock Adjust system clock when changing local RTC mode Commands: status Show current time settings set-time TIME Set system time set-timezone ZONE Set system time zone list-timezones Show known time zones set-local-rtc BOOL Control whether RTC is in local time set-ntp BOOL Control whether NTP is enabled

查看当前设置,直接输入timedatectl等同于timedatectl status

[root@tgcdn-qd-133 /root]#   timedatectl 
                             Local time: Tue 2018-03-13 10:41:20 CST
                             Universal time: Tue 2018-03-13 02:41:20 UTC
                             RTC time: Tue 2018-03-13 02:42:29
                             Time zone: Asia/Shanghai (CST, +0800)
                             NTP enabled: n/a
                             NTP synchronized: no
                             RTC in local TZ: no
                             DST active: n/a


设置当前时间:

timedatectl set-time HH:MM:SS

设置当前日期:

timedatectl set-time YYYY-MM-DD

默认的,系统是使用UTC时间的,可以用以下命令打开和关闭UTC时间:

timedatectl set-local-rtc boolean

把 boolean 替换成yes则表示使用本地时间,替换成no则表示是UTC时间

注:这里的boolean值也可以用true、flase

设置时区:

查看所有的时区:

timedatectl list-timezones

设置时区

timedatectl set-timezone time_zone

远程NTP服务器同步

timedatectl还可以设置是否打开NTP选项

timedatectl set-ntp boolean

这里的boolean是yes或者no

除了以上用法,timedatectl 还支持通过-H参数进行远程主机的时间设置。

查看系统时间

[root@nginx ~]# date
2018年 03月 13日 星期二 10:58:41 CST

查看硬件时间

[root@nginx ~]# hwclock --show
2018年03月13日 星期二 11时00分16秒  -0.086030 秒

假如系统时间和硬件时间都不准确

更新时区

[root@localhost ~]# timedatectl set-timezone Asia/Shanghai

更新日期

[root@localhost ~]# timedatectl set-time 2017-06-13

更新时间

[root@localhost ~]# timedatectl set-time 2017-06-13

将系统时间和硬件时间调整为一致

[root@localhost ~]# timedatectl set-local-rtc 1
或者
[root@localhost ~]# hwclock --systohc --localtime

将日期写入CMOS

[root@localhost ~]# clock –w
 
 


原文地址:https://www.cnblogs.com/qinshizhi/p/9572234.html