javascript时钟

<html>
     <head>
     <script type="text/javascript">
     function startTime()
     {
     var today=new Date()--获得当天日期

     var year=today.getYear()--获得年份
     var month=today.getMonth()--获得月份
     var day=today.getDate()--获得日期,注意不是getDay(),getDay()是获得星期

     var h=today.getHours()
     var m=today.getMinutes()
     var s=today.getSeconds()

     m=checkTime(m)
     s=checkTime(s)

     document.getElementById('clock').value=year+"-"+month+"-"+day+"  "+h+":"+m+":"+s
     t=setTimeout('startTime()',500)
     }

     function checkTime(i)
     {
     if (i<10) 
       {i="0" + i}
       return i
     }
     </script>
     </head>
     <body onload="startTime()">
          <input id="clock" />
     </body>
</html>

posted on 2008-12-07 10:42  Junephy  阅读(77)  评论(0)    收藏  举报

导航