得到第1,最后,今天约会

时间:2011-04-26 22:19:39

标签: javascript date

我如何获得今天的日期,当月的第一天和当月的最后一天?

2 个答案:

答案 0 :(得分:5)

see fiddle

var current = new Date();           // this one's pretty self explanatory

console.log('current: ' + current);

var last = new Date();
last.setMonth(last.getMonth() + 1); // go to next month 
last.setDate(0);                    // setting date to 0 is last day of previous month

console.log('last: ' + last);

var first = new Date();
first.setDate(1);                   // setting date to 1 is first day of current month

console.log('first: ' + first);

答案 1 :(得分:0)