六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 111|回复: 0

javascript笔记整理之日期

[复制链接]

升级  40%

4

主题

4

主题

4

主题

童生

Rank: 1

积分
20
 楼主| 发表于 2013-2-7 20:40:35 | 显示全部楼层 |阅读模式
JS获取当前各种日期格式<script language="javascript">var myDate=new Date();   document.write(myDate.getYear().toString()+"<br>");//获取当前年份(2位)   document.write(myDate.getFullYear().toString()+"<br>");//获取当前完整的年份(4位,1970-????)   document.write(myDate.getMonth().toString()+"<br>");//获取当前月份(0-11,0代表1月)   document.write(myDate.getDate().toString()+"<br>");//获取当前日(1-31)   document.write(myDate.getDay().toString()+"<br>");//获取当前星期X(0-6,0代表星期天)   document.write(myDate.getTime().toString()+"<br>");//获取当前时间(从1970-1-1开始的毫秒数)   document.write(myDate.getHours().toString()+"<br>");//获取当前小时数(0-23)   document.write(myDate.getMinutes().toString()+"<br>");//获取当前分钟数(0-59)   document.write(myDate.getSeconds().toString()+"<br>");//获取当前秒数(0-59)   document.write(myDate.getMilliseconds().toString()+"<br>");//获取当前毫秒数(0-999)   document.write(myDate.toLocaleDateString().toString()+"<br>");//获取当前日期</script> 
js获取当月的最后一天 Html代码 <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 newnew_date = new Date(new_year,new_month,1);                //取当年当月中的第一天    return (new Date(new_date.getTime()-1000*60*60*24)).getDate();//获取当月最后一天日期   }   </script>  <body>      <input id="Button1" type="button" value="取2007年5月的最后一天"  />  </body>  </html>   
 
 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表