JavaScript gets a few months in the past

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.