-----------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