JS獲取當年當月最后一天日期


<html xmlns="http://www.w3.org/1999/xhtml" > 
<meta charset="UTF-8"> 
<head> 
<title>獲取當年當月最后一天日期</title> 
<script language="javascript"> 
function getLastDay(){ 
  var year = document.getElementById('year').value;
  var month = document.getElementById('month').value;
  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); //取當年當月中的第一天 
  return (new Date(new_date.getTime()-1000*60*60*24)).getDate();//獲取當月最后一天日期 
} 
</script> 
<body> 
year:<input id="year" value="" type="text">
<br />
mont:<input id="month" value="" type="text">
<br />
<input id="Button1" type="button" value="最后一天" onClick="alert(getLastDay())" /> 
</body> 
</html>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM