admin 管理员组

文章数量: 1184232

1.查看系统当前时间

[root@foundation58 Desktop]# date
Wed Dec  4 14:47:53 CST 2019

2.修改系统时间(重启失效)

[root@foundation58 Desktop]# date -s "2019-12-4 14:47:00"
Wed Dec  4 14:47:00 CST 2019
[root@foundation58 Desktop]# date
Wed Dec  4 14:47:03 CST 2019

3.修改系统时间(重启不失效)

[root@foundation58 ~]# date -s "2019-12-4 14:33:00" && hwclock --systohc
Wed Dec  4 14:33:00 CST 2019
[root@foundation58 ~]# date
Wed Dec  4 14:33:07 CST 2019

原理:

命令hwclock –systohc会将当前系统时间同步至硬件时间。
硬件时间,即主板CMOS的时间,大约11分钟同步一次系统时间。

hwclock详细用法:

[root@foundation58 kiosk]# hwclock --help
Usage:
 hwclock [function] [option...]
Functions:
 -h, --help           show this help text and exit
 -r, --show           read hardware clock and print result
     --set            set the RTC to the time given with --date
 -s, --hctosys        set the system time from the hardware clock
 -w, --systohc        set the hardware clock from the current system time
     --systz          set the system time based on the current timezone
     --adjust         adjust the RTC to account for systematic drift since
                        the clock was last set or adjusted
 -c, --compare        periodically compare the system clock with the CMOS clock
     --getepoch       print out the kernel's hardware clock epoch value
     --setepoch       set the kernel's hardware clock epoch value to the 
                        value given with --epoch
     --predict        predict RTC reading at time given with --date
 -V, --version        display version information and exit
Options:
 -u, --utc            the hardware clock is kept in UTC
     --localtime      the hardware clock is kept in local time
 -f, --rtc <file>     special /dev/... file to use instead of default
     --directisa      access the ISA bus directly instead of /dev/rtc
     --badyear        ignore RTC's year because the BIOS is broken
     --date <time>    specifies the time to which to set the hardware clock
     --epoch <year>   specifies the year which is the beginning of the
                        hardware clock's epoch value
     --noadjfile      do not access /etc/adjtime; this requires the use of
                        either --utc or --localtime
     --adjfile <file> specifies the path to the adjust file;
                        the default is /etc/adjtime
     --test           do not update anything, just show what would happen
 -D, --debug          debugging mode

本文标签: 修改系统 编程 系统中的