Finishing:
If you need to get the last few months, involving the cross-year, how to achieve the problem, took some time, the code is as follows:
/** Epoch time get last 12 months * * @num number of incoming month **/ (functiongetMonth (num) {var_curdate =NewDate (), _curtime= _curdate.gettime (),//Current era time_onedaytime = 24 * 3600 * 1000,//the total number of milliseconds in a day_thismonsumday =NewDate (_curdate.getfullyear (), _curdate.getmonth () + 1, 0). GetDate ();//total number of days in the current month var_resultarr = []; for(vari = 1, j = _curtime; I <= num; i++, J-= _thismonsumday *_onedaytime) { //Monthly Iteration if(_resultarr.length >=num) { Break; } //the time point of the month, as the current month basis var_thismonth =NewDate (j); //re-assignment current month days_thismonsumday =NewDate (_thismonth.getfullyear (), _thismonth.getmonth () + 1, 0). GetDate (); _resultarr.push (DateFormat ("Yyyy-mm",NewDate (j))); } return_resultarr; })(38);
Welcome to all kinds of shooting bricks
JavaScript gets a few months in the past