一、查看及设置日期时间
1.查看日期时间
date查看日期时间
−格式:date +"显示格式"
−显示格式中可以添加字符串,使用特定%变量(若用在crontab记录中应使用\%)
[root@hadoop ~]# date
Sun May 1 02:08:04 CST 2022 //默认格式显示
[root@hadoop ~]# date +"%Y-%m-%d %H:%M"
2022-05-01 02:10 //提取日期时刻
在文件名中嵌入日期时间信息
−命令替换机制:$(命令行)
[root@hadoop ~]# touch file-$(date +%Y%m%d).txt //文件名嵌入当天日期
[root@hadoop ~]# ls file*
file1 file{1..5.txt} file1.txt file2 file-20220501.txt
2.设置日期时间
date设置日期时间
−用法1:date mmddHHMMYYYY
−用法2:date -s "YYYY-mm-ddHH:MM"
[root@hadoop ~]# date -s "2022-08-15 20:18" //更改日期时间
Mon Aug 15 20:18:00 CST 2022
[root@hadoop ~]# date //确认结果
Mon Aug 15 20:18:03 CST 2022
二、硬件时钟调校
1.校对系统时钟
以主板BIOS时钟为标准,重设系统时钟
−hwclock-s
−或者hwclock--hctosys
[root@hadoop ~]# date
Mon Aug 15 20:19:11 CST 2022
[root@hadoop ~]# hwclock -s //重设为BIOS硬件时钟
[root@hadoop ~]# date /确认结果
Mon Aug 15 20:19:45 CST 2022
2.校对BIOS硬件时钟
以系统时钟为标准,重设主板BIOS的硬件时钟
−hwclock-w
−或者hwclock--systohc
[root@hadoop ~]# date -s'2022-08-15 20:22' //先设置准确系统时钟
Mon Aug 15 20:22:00 CST 2022
[root@hadoop ~]# hwclock -w //校对BIOS硬件时钟