得到今天的第一天,最后一天

问题描述:

如何得到今天的日期,本月的第一天和本月的最后一天?得到今天的第一天,最后一天

+1

重新标记; jQuery没有日期函数,所以这是一个普通的JavaScript问题。 – ThiefMaster 2011-04-26 22:21:09

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); 
+0

+1我不知道Date支持环绕。 – 2011-04-26 22:31:27