如何获得该月的最后一天

如何以时间戳为晚上11:59:59获取当月的最后一天?

这将给你当月的最后一天。

var t= new Date(); alert(new Date(t.getFullYear(), t.getMonth() + 1, 0, 23, 59, 59)); 
 function LastDayOfMonth(Year, Month) { return new Date((new Date(Year, Month, 1)) - 1); } console.log(LastDayOfMonth(2009, 11)) 
 var d = new Date(); console.log(d); d.setMonth(d.getMonth() + 1); // set month as next month console.log(d); d.setDate(0); // get the last day of previous month console.log(d); 
 var d = new Date(); m = d.getMonth(); //current month y = d.getFullYear(); //current year alert(new Date(y,m,1)); //this is first day of current month alert(new Date(y,m+1,0)); //this is last day of current month 

这个月的最后一天

 now = new Date lastDayOfTheMonth = new Date(1900+now.getYear(), now.getMonth()+1, 0) 

http://coffeescriptcookbook.com/chapters/dates_and_times/finding-last-day-of-the-month

 var month = 1; // 1 for January var d = new Date(2015, month, 0); console.log(d); // last day in January 

有时,您拥有的是当月的文本版本,即:2017年4月。

 //first and last of the current month var current_month = "April 2017"; var arrMonth = current_month.split(" "); var first_day = new Date(arrMonth[0] + " 1 " + arrMonth[1]); //even though I already have the values, I'm using date functions to get year and month //because month is zero-based var last_day = new Date(first_day.getFullYear(), first_day.getMonth() + 1, 0, 23, 59, 59); //use moment,js to format var start = moment(first_day).format("YYYY-MM-DD"); var end = moment(last_day).format("YYYY-MM-DD"); 
 Calendar cal = Calendar.getInstance(); cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); Date lastDayOfMonth = cal.getTime();