1. Using the DATE-D option
Date + "%y%m%d"-D "+n days" today's post N day dates
Date + "%y%m%d"-D "-N days" today's top N Day dates
2. Common date format
Python
[[email protected] tmp] # date + "%F"
--
[[email protected] tmp] # date + "%d"
///
[[email protected] tmp] # date + "%y%m%d%h:%m:%s"
20120608 : £º
[[email protected] tmp] # date + "%y%m%d"
20120608
[[email protected] tmp] # date + "%y%m%d%h:%m:%s"-D "+1 hours"
20120608 : £º
[[email protected] tmp] # date + "%y%m%d%h:%m:%s"-D "+1 days"
20120609 ::
[[email protected] tmp] # date + "%y%m%d%h:%m:%s"-D "+1 months"
20120708 :
[[email protected] tmp] # date + "%y%m%d%h:%m:%s"-D "+1 years"
20130608 : </pre><prename="code" class= "PHP">[[email protected] tmp]# date + "%T"
in thefollowing:
[[email protected] tmp] # date + "%F%T"
A-on:
[[email protected] tmp] # date + "%d%T"
Php
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s"
2012-07-18 05:17:01
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D "+10hour"
2012-07-18 15:17:16
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D "+24hour"
2012-07-19 05:17:37
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D " -24hour"
2012-07-17 05:17:45
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D " -20minute"
2012-07-18 04:58:00
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D "+20minute"
2012-07-18 05:38:05
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D "+2day"
2012-07-20 05:18:15
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D " -2day"
2012-07-16 05:18:19
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D " -2month"
2012-05-18 05:18:24
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D "+2month"
2012-09-18 05:18:28
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D "+2year"
2014-07-18 05:18:32
[[email protected] riqi]# date +"%y-%m-%d%h:%m:%s" -D " -2year"
2010-07-18 05:18:36
Using the shell to turn the time string and time stamp to each other
date +%s can get Unix timestamp;
use the shell to turn the time string with the timestamp:
date-d "2010-10-18 00:00:00" +%s output shape: 1287331200
and the time stamp is converted to a string to do this:
date-d @1287331200 "+%y-%m-%d" output shape such as: 2010-10-18
If you need to get the days before and after the specified date, you can:
1, seconds= ' date-d "2010-10-18 00:00:00" +%s ' #得到时间戳
2. seconds_new= ' expr $seconds + 86400 ' #加上一天的秒数86400
3, date_new= ' date-d @ $seconds _new "+%y-%m-%d" ' #获得指定日前加上一天的日前
This article is from the "Guangzhou Linux operation and Maintenance" blog, please be sure to keep this source http://milenovo.blog.51cto.com/10554394/1694592
Shell Date Time addition minus