I am using below to get previous, current and the next month under Ubuntu
11.04:
LAST_MONTH=`date +'%m' -d 'last month'`
NEXT_MONTH=`date +'%m' -d 'next month'`
THIS_MONTH=`date +'%m' -d 'now'`
It works well until today, the last day of October, 2012 (2012-10-31)
I get below result as of now:
$ date
Wed Oct 31 15:35:26 PDT 2012
$ date +'%m' -d 'last month'
10
$ date +'%m' -d 'now'
10
$ $ date +'%m' -d 'next month'
12
I suppose the outputs should be 9
,10
,11
respectively.
Don't understand why date
outputs behave like this. What should be a good way to get consistant previous
, current
and next
month instead?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…