Linux常用命令之date命令

-----------date命令-----------
1.时间的显示(获取)操作

[root@localhost shell]# date +%Y    #显示年(完整数字)
2017
[root@localhost shell]# date +%y    #显示年
17
[root@localhost shell]# date +%m    #显示月份
02
[root@localhost shell]# date +%d    #显示天
11
[root@localhost shell]# date +%h    #显示月份(中文)
2月
[root@localhost shell]# date +%H    #显示小时
14
[root@localhost shell]# date +%M    #显示分钟
28
[root@localhost shell]# date +%S      #显示秒
11
[root@localhost shell]# date +%s        #显示时间戳(当前时间的时间戳)
1486794493
[root@localhost shell]# date -d @100      #显示100秒的时间戳对应时间
1970年 01月 01日 星期四 08:01:40 CST
[root@localhost shell]# date -d @1486794493    #当前时间戳对应的时间
2017年 02月 11日 星期六 14:28:13 CST
[root@localhost shell]# date +"%Y-%m-%d %H:%M:%S"  #显示当前时间
2017-02-11 14:37:44

2.对时间的计算操作

[root@localhost shell]# date           #当前时间
2017年 02月 11日 星期六 14:40:50 CST
#如果提示"%F %T"无效,则去掉该参数
#如 date -d "-1 day"   #即可。
[root@localhost shell]# date -d "-1 day" +"%F %T" 	#一天前的时间
2017-02-10 14:41:10
[root@localhost shell]# date -d "+1 day" +"%F %T" #明天这个时候
2017-02-12 14:41:14
[root@localhost shell]# date -d "+1 month" +"%F %T"  #下个月这个时候
2017-03-11 14:41:25
[root@localhost shell]# date -d "+1 year" +"%F %T"  #一年后
2018-02-11 14:41:33
[root@localhost shell]# date -d "+1 week" +"%F %T"   #一周后
2017-02-18 14:41:40
[root@localhost shell]# date -d "+1 hour" +"%F %T"   #一小时后
2017-02-11 15:41:45
[root@localhost shell]# date -d "-10 min" +"%F %T"   #十分钟前
2017-02-11 14:32:21
[root@localhost shell]# date -d "-10 sec" +"%F %T"   #十秒钟前
2017-02-11 14:42:16
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

执子之意

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值