javascript的Date操作(月初,月末)

var cur = new Date(),
    unitDay = 24 * 60 * 60 * 1000;
//月初
var sFirstDay = cur.getFullYear() + '/' + (cur.getMonth()+1) + '/01 00:00:00';
var firstDay = new Date(sFirstDay);
//月末
var lastDay = new Date(sFirstDay);
lastDay.setMonth(lastDay.getMonth() + 1);


//月初
var firstDay = new Date(+cur);
firstDay.setDate(1);
//月末
var lastDay = new Date(+firstDay);
lastDay.setMonth(lastDay.getMonth() + 1);
lastDay.setDate(0);


//生成当前月份
var lastDate = lastDay.getDate();
var firstTime = +firstDay;
for (var i = 0; i < lastDate; i++) {
    dateList.push(new Date(firstTime + i * unitDay));
}

 

posted @ 2017-12-19 18:35  全玉  阅读(1977)  评论(0编辑  收藏  举报