码迷,mamicode.com
首页 > Web开发 > 详细

js获取实时日期和时间

时间:2014-12-02 08:55:04      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:style   io   ar   sp   java   on   div   bs   cti   

//在相应位置显示时间日期

<div style=" width:400px; height:50px">
    <span id="showtime"></span>     <!--走马灯文字 <marquee direction="left">需要滚动的内容</marquee>-->
    </div>
</body>

 

js获取时间日期

<script type="text/javascript">
function showTime(){
 var week=new Array(‘星期一‘,‘星期二‘,‘星期三‘,‘星期四‘,‘星期五‘,‘星期六‘,‘星期日‘);
 var now = new Date();
 var year = now.getFullYear();
 var month = now.getMonth();
 var date = now.getDate();
 var day = now.getDay();
 var hour = now.getHours();
 var minutes = now.getMinutes();
 var second = now.getSeconds();
     month<10?month=‘0‘+month:month;
     month=month+1;
     hour<10?hour=‘0‘+hour:hour;
     minutes<10?minutes=‘0‘+minutes:minutes;
     second<10?second=‘0‘+second:second;
     var now_time = ‘当前时间:‘ + year + ‘年‘ + month + ‘月‘ + date + ‘日‘ + ‘ ‘ + hour + ‘:‘ + minutes + ‘:‘ + ‘‘ + second + ‘ ‘ + week[day - 1];
     document.getElementById(‘showtime‘).innerHTML=now_time;
     setTimeout("showTime();",1000);      //每隔1秒刷新一次
 }
</script>

 

js获取实时日期和时间

标签:style   io   ar   sp   java   on   div   bs   cti   

原文地址:http://www.cnblogs.com/fengmingming/p/4136495.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!