js获取实时日期和时间

mac2022-06-30  22

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

<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>

 

转载于:https://www.cnblogs.com/fengmingming/p/4136495.html

最新回复(0)