个人觉得很好用,不用傻乎乎去计算
linux中用shell获取昨天、明天或多天前的日期
# -d, --date=STRING display time described by STRING, not `now’
date --date="next-day " +%Y%m%d 明天
[root@Gman root]# date -d "next-day" +%Y%m%d #明天日期
2. 20091024
[root@Gman root]# date -d "last-day" +%Y%m%d #昨天日期
20091022
[root@Gman root]# date -d "yesterday" +%Y%m%d #昨天日期
20091022
[root@Gman root]# date -d "tomorrow" +%Y%m%d # 明天日期
20091024
[root@Gman root]# date -d "last-month" +%Y%m #上个月日期
200909
[root@Gman root]# date -d "next-month" +%Y%m #下个月日期
200911
. [root@Gman root]# date -d "next-year" +%Y #明年日期
2010
DATE=$(date +%Y%m%d --date '2 days ago') #获取昨天或多天前的日期