Linux战地日记—date命令详细示例

date命令详细示例


日期格式:年/月/日 和 月/日/年

[bestcoder@localhost chapter1]$ date +%F
2015-10-14
[bestcoder@localhost chapter1]$ date +%D
10/14/15

显示几天前/后,几年前/后

[bestcoder@localhost chapter1]$ date +%D -d '-3 days'
10/11/15
[bestcoder@localhost chapter1]$ date +%F -d '+3 days'
2015-10-17
[bestcoder@localhost chapter1]$ date +%F -d '-1 year'
2014-10-14
[bestcoder@localhost chapter1]$ date +%F -d '-3 year'
2012-10-14

显示时间,几小时前/后

[bestcoder@localhost chapter1]$ date +%T
08:04:07
[bestcoder@localhost chapter1]$ date +%T -d '3 hours'
11:05:43
[bestcoder@localhost chapter1]$ date +%T -d '-2 hours'
06:05:07


显示当前日期的时间戳

[bestcoder@localhost chapter1]$ date +%s
1444835173

根据时间戳显示时间

[bestcoder@localhost chapter1]$ date -d "@1444835173"
Wed Oct 14 08:06:13 PDT 2015



你可能感兴趣的:(linux战地日记)