在linux里有两个时钟:
硬件时钟、系统时钟(内核中的时钟)
所以有两个不同的命令: date命令、hwclock命令
1.系统时钟
输入date查看系统时钟:
如果觉得不方便也可以指定格式显示日期,需要在字符串前面加”+”
如下图所示,输入了 date “+ %Y/%m/%d %H:%M:%S”
%M:表示秒
%m:表示月
%Y:表示年,当只需要最后两位数字,输入%y即可
date命令设置时间格式如下:
date 月日时分年.秒
如下图所示,输入date 111515292017.20,即可设置好系统时钟
2.硬件时钟
hwclock命令使用:
常用参数如下所示
-r, --show 读取并打印硬件时钟(read hardware clock and print result )
-s, --hctosys 将硬件时钟同步到系统时钟(set the system time from the hardware clock )
-w, --systohc 将系统时钟同步到硬件时钟(set the hardware clock to the current system time )
如下图所示,使用hwclock -w,即可同步硬件时钟
然后重启后,使用date命令,看到时间正常