1. date-d operation
Date +"%y%m%d" -D "+ndays" #今天的后n天日期 Date +"%y%m%d" -D "-ndays" #今天的前n天日期
2. Common Date format output
Date+"%F"#输出: -- .- ,Date+"%d"#输出: ./ ,/ ADate+"%y%m%d%h:%m:%s"#输出:20120608 Geneva: the: -Date+"%y%m%d"#输出:20120608Date+"%y%m%d%h:%m:%s"-D"+1 hours"#输出:20120608 to: the: +Date+"%y%m%d%h:%m:%s"-D"+1 Days"#输出:20120609 Geneva: the: theDate+"%y%m%d%h:%m:%s"-D"+1 months"#输出:20120708 Geneva: the: AboutDate+"%y%m%d%h:%m:%s"-D"+1 years"#输出:20130608 Geneva: -: -Date+"%T"#输出: to:Geneva: +Date+"%F%T"#输出: -- .- , to:Geneva: theDate+"%d%T"#输出: ./ ,/ A to:Geneva: the
3. Date format Conversion
# string to TimestampDate-D"2010-10-18 00:00:00"+%s #输出:1287331200# Timestamp to StringDate-D @1287331200 "+%y-%m-%d"#输出: .-Ten- -# Gets the last n days of the specified date, if it is the first n days, then the middle of the second part is-Step 1:Get time stampseconds=`Date-D"2010-10-18 00:00:00"+%s '
Step 2:Plus the number of seconds in N days 86400*nseconds_new=`Expr$seconds +86400*n '
Step 3:Get a date plus a day before the specified datedate_new=`Date-D @ $seconds _new"+%y-%m-%d"`
In-Shell date operations