今天是2012-04-22
date -d "+1 day" +%Y-%m-%d
shell脚本中执行:$(date -d "+1 day" "+%Y-%m-%d")
2012-04-23
date -d "-1 day" +%Y-%m-%d
2012-04-21
date -d "2012-04-10 -1 day " +%Y-%m-%d
2012-04-09
date -d "2012-04-10 +1 day " +%Y-%m-%d
2012-04-11
date -d "-1 week " +%Y-%m-%d
2012-04-15
date -d "+1 week " +%Y-%m-%d
2012-04-29
date -d "+1 month " +%Y-%m-%d
2012-05-22
date -d "-1 month " +%Y-%m-%d
2012-03-22
date -d "-1 year " +%Y-%m-%d
2011-04-22
date -d "+1 year " +%Y-%m-%d
2013-04-22
日期作为参数,以下两种写法一致:
date1=$(date)
date2=$(date -d "$date1 -1 day" '+%Y-%m-%d')
date3=$(date -d "$(date)" '+%Y-%m-%d')
date1="2016-11-17"
date2=$(date -d "$date1 -1 day" '+%Y-%m-%d')
date3=$(date -d "$date1" '+%Y-%m-%d')
echo $date1
echo $date2
echo $date3
原贴地址:http://blog.sina.com.cn/s/blog_ad6555610101b5ud.html