jsはどうやって先月の最初の日と最後の日を獲得しますか?

574 ワード

    
    var nowdays = new Date();
    var year = nowdays.getFullYear();
    var month = nowdays.getMonth();
    if(month==0)
    {
        month=12;
        year=year-1;
    }
    if (month < 10) {
        month = "0" + month;
    }
    var firstDay = year + "-" + month + "-" + "01";//       

    

    var myDate = new Date(year, month, 0);
    var lastDay = year + "-" + month + "-" + myDate.getDate();//        
参考資料:jsはどうやって先月の初日と最後の日を取得しますか?   http://www.studyofnet.com/news/1180.html