<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <body> <script> //获取当月最后一天日期 function getLastDay(year,month) { var new_year = year; //取当前的年份 var new_month = month++;//取下一个月的第一天,方便计算(最后一天不固定) if(month>12) //如果当前大于12月,则年份转到下一年 { new_month -=12; //月份减 new_year++; //年份增 } var new_date = new Date(new_year,new_month,1); //取当年当月中的第一天 alert(new_date.getTime()); return (new Date(new_date.getTime()-1000*60*60*24)).getDate();//获取当月最后一天日期 } //获取当前月日期起始 var date = new Date(); year = date.getYear(); month = date.getMonth()+1; //获取当前月上月日期 date.setMonth(date.getMonth()-1); lastDateOfYear = date.getYear(); lastDateOfMonth = date.getMonth()+1; alert(year+"-"+month+"-"+getLastDay(year,month)); alert(lastDateOfYear+"-"+lastDateOfMonth+"-"+"1"); </script> </body> </html>
当月获取最后一天&&上个月日期
猜你喜欢
转载自lncdzh.iteye.com/blog/2299751
今日推荐
周排行