查看当前系统时间:

[root@ifx142 ~]# date

2020年 06月 24日 星期三 20:05:34 CST

linux界面更改时间(linux基础---修改系统时间)(1)

修改当前系统时间:

[root@ifx142 ~]# date -s '2020-06-24 12:20:20'

2020年 06月 24日 星期三 12:20:20 CST

[root@ifx142 ~]# date

2020年 06月 24日 星期三 12:20:21 CST

获取当前年份:

date %Y

获取当前月份:

date %m

获取当前日期:

date %d

获取当前小时:

date %H

获取当前分钟:

date %M

获取当前日期:

date %S

获取前后n天的时间:

[root@ifx142 ~]# date %Y-%m-%d -d "-3 days"

2020-06-21

[root@ifx142 ~]# date %Y-%m-%d -d "3 days"

2020-06-27

[root@ifx142 ~]# date

2020年 06月 24日 星期三 12:26:53 CST

[root@ifx142 ~]# date %H:%M:%S -d "3 hours";date

15:29:21

2020年 06月 24日 星期三 12:29:21 CST

[root@ifx142 ~]# date %H:%M:%S -d "-3 hours";date

9:29:21

2020年 06月 24日 星期三 12:29:21 CST

上述命令的解释:

date %H:%M:%S 其实是定义输出结果的显示格式

-d "-3 hours" 用来计算和当前时间的差值

,