The date command is very often used, in addition to entering date directly, more often than not, we want to output in a specific format, each time before using the turn of Man or--help, write down to deepen the impression. Arguments to the date command can use the "+" number, which is to facilitate the output of dates in a particular format; use: date [options] [+ format] option:-D,--Date #显示指定字符串的时间而非当前时间
Format:%Y #表示年%m #表示月%d #表示天%H #表示小时 (00-23)%k #表示小时 (0-23)%I (capital I) #表示小时 (01-12)%l (lowercase L) #表示小时 ( 0-12)%m #表示分钟 (00-59)%P #AM/pm%s #表示秒%s #unix时间戳
Example:
#特定格式输出
> Date +%y%m%d
20150527
> Date +%y-%m-%d
2015-05-27
> Date "+%y-%m-%d%h:%m:%s"
2015-05-27 09:41:04
#输出明天
> date-d Tomorrow "+%y-%m-%d"
2015-05-28
#输出昨天
> date-d Yesterday "+%y-%m-%d"
2015-05-26
#输出特定字符串的日期
> date-d "20150424"
Fri Apr 00:00:00 CST 2015< C15/>> date-d "20150424 12:12:12"
Fri Apr 12:12:12 CST 2015
> date-d "2015-04-24"
Fri Apr 24 00: 00:00 CST 2015
#按指定格式输出特定字符串的日期
> date-d "20150424" "+%y-%m-%d"
2015-04-24
#输出指定时间差的日期
> date-d "+1 Day"
Thu could 09:49:47 CST 2015
> date-d "-1 Day" "+%y-%m-%d"
2015-05-26
> D Ate-d "-2 Day" "+%y-%m-%d"
2015-05-25
> date-d "-2 Days" "+%y-%m-%d"
2015-05-25
> date-d "-2 Day "" +%y-%m-%d "
2015-05-25
> date-d"-2 Week "" +%y-%m-%d "
2015-05-13
> date-d"-2 Month "" +% y-%m-%d "
2015-03-27
> date-d"-2 Year "+%y-%m-%d"
2013-05-27