Linux时钟设置-硬件时钟与软件时钟

Linux里分硬件时钟与系统时钟等两种时钟。

1.硬件时钟:

(1)定义:硬件时钟是存储在主板上CMOS里的时钟,关机后该时钟依然运行,主板的电池为它供电。对应于嵌入式设备有一个RTC(Real time clock)模块。硬件时钟即RTC时钟。

(2)硬件时钟设置命令:hwclock
hwclock命令,与clock命令是同一个命令,主要用来查询和设置硬件时钟。

命令选项:
-r, --show 读取并打印硬件时钟(read hardware clock and print result )。

(3)示例
[root@localhost ~]# hwclock --show
2021年01月22日 星期五 17时10分52秒 -0.837405 秒

[root@localhost ~]# hwclock
2021年01月22日 星期五 17时11分26秒 -0.089443 秒

[root@localhost ~]# hwclock -r
2021年01月22日 星期五 17时17分24秒 -0.868884 秒

2、系统时钟:

(1)定义:系统时钟是Kernel中的时钟,所有Linux相关指令与函数都是读取系统时钟的设定。

(2)系统时钟设置命令:date

(3)示例:

a.显示系统时间(date )

[root@localhost ~]# date
2021年 01月 22日 星期五 17:29:36 CST

b.更改时间(date -s)

*如:*将日期设置为2014年6月28日
[root@localhost ~]# date -s 06/28/14
2014年 06月 28日 星期六 00:00:00 CST

*如:*将时间设置为14点20分50秒
[root@localhost ~]# date -s 14:20:50
2014年 06月 28日 星期六 14:20:50 CST

*如:*将时间设置为2014年6月18日14点16分30秒(MMDDhhmmYYYY.ss)
[root@localhost ~]# date 0628141614.30
2014年 06月 28日 星期六 14:16:30 CST

3.系统时钟与硬件时钟的关系:

(1)软件启动时系统时钟会去读取硬件时钟,之后则独立运行。

(2)使用不同参数设置,hwclock命令既可以将硬件时钟同步到系统时钟,也可以将系统时钟同步到硬件时钟。 (备注: hwclock命令与clock命令是一个东西)

命令选项:
-s, --hctosys 将硬件时钟同步到系统时钟(set the system time from the hardware clock )
-w, --systohc 将系统时钟同步到硬件时钟(set the hardware clock to the current system time )

示例
[root@localhost ~]# hwclock --systohc

猜你喜欢

转载自blog.csdn.net/woshisunyizhen/article/details/112993283