Home > Web Front-end > JS Tutorial > body text

js获取某月的最后一天日期的简单实例_javascript技巧

WBOY
Release: 2016-05-16 17:31:38
Original
1349 people have browsed it

复制代码 代码如下:

  //获得某月的最后一天 
        function getLastDay(year,month) {        
             var new_year = year;    //取当前的年份         
             var new_month = month++;//取下一个月的第一天,方便计算(最后一天不固定)         
             if(month>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();//获取当月最后一天日期         
        } 

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template