首页 > Web开发 > 详细

js获取实时日期和时间

时间:2014-12-02 08:54:33      阅读:287      评论:0      收藏:0      [点我收藏+]

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

<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获取实时日期和时间

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!