编写一个javascript函数,返回一个数组,其中包含了最近12月:
//Make some functions as tools //return array function getLast12Months(){ var last12Months = []; var today = new Date(); today.setMonth(today.getMonth()+1); for(var i=0;i<12;i++){ var lastMonth = today.setMonth(today.getMonth()-1); last12Months[11-i] = today.getFullYear() + "-" + fillZero((Number(today.getMonth())+1),2); } return last12Months; }
结果的形式如下:
[ '2013-05', '2013-06', '2013-07', '2013-08', ....]