zoukankan      html  css  js  c++  java
  • 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>
    

      

  • 相关阅读:
    51nod1260
    51nod1327
    51nod1342
    51nod1479
    LOJ6088
    51nod1634
    51nod1778
    JAVA循环结构学校上机经常遇到的几题 笔记
    B. The Number of Products(Codeforces Round #585 (Div. 2))
    A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
  • 原文地址:https://www.cnblogs.com/mracale/p/8351646.html
Copyright © 2011-2022 走看看