jquery获取当年月天数以及当月的最后一天|当月的天数

来源:互联网 发布:黑苹果windows双系统 编辑:程序博客网 时间:2024/06/05 12:40
<html xmlns="http://www.w3.org/1999/xhtml" >       <head>       <title>标题页</title>       <script language="javascript">       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);                //取当年当月中的第一天          var date_count =   (new Date(new_date.getTime()-1000*60*60*24)).getDate();//获取当月的天数        var last_date =   new Date(new_date.getTime()-1000*60*60*24);//获得当月最后一天的日期return date_count;}        </script>       <body>           <input id="Button1" type="button" value="取2007年5月的最后一天" onClick="alert(getLastDay(2007,5))" />       </body>       </html>  



转载地址:http://blog.csdn.net/sanyuesan0000/article/details/7967667

上面是获取年月份,再算数当月的天数。


下面的例子是直接获取当月的天数。


<span style="font-size:18px;">function getLastMaxDay(this_date){    var mon=(0==$.trim(this_date).substring(4,5))?$.trim(this_date).substring(5,6):$.trim(this_date).substring(4,6);    var day="";    var year_mon="";    if(mon>10){        mon=mon-2;    }else if(mon==10){        mon=mon-2;    }else{        mon=mon-2;    }    var year=$.trim(this_date).substring(0,4);    var dt = new Date(year,mon,1);      //var dt = new Date();          dt.setDate(1);          dt.setMonth(dt.getMonth()+1);          cdt = new Date(dt.getTime()-1000*60*60*24);       return cdt.getDate();}//去除最后的逗号function toIdsForIn(id){    var arr=(id+"").split(',');     return arr.join("','");}</span>




转载地址:http://yangjian-tongxue.blog.163.com/blog/static/107580932201321410815620/
0 0
原创粉丝点击