MySQL, Oracle, Linux, 软件架构及大数据技术知识分享平台

网站首页 > linux / 正文

linux基础---修改系统时间

2024-11-26 15:29 huorong linux 4 ℃ 0 评论

查看当前系统时间:

[root@ifx142 ~]# date

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

修改当前系统时间:

[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" 用来计算和当前时间的差值

Tags:linux获取系统时间

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言