Reputation: 83
Set the date:
var a = new Date('2013.12.31');
Output:
Tue Dec 31 2013 00:00:00 GMT+0800 (China Standard Time)
Modify date:
a.setMonth(a.getMonth()-1);
Modified output:
Sun Dec 01 2013 00:00:00 GMT+0800 (China Standard Time)
Upvotes: 2
Views: 60
Reputation: 38079
30 days has September, April, June, and November. Subtracting 1 from the month portion of Dec 31 gives you Nov 31. Since Nov only has 30 days, the extra day puts it into December.
Upvotes: 7