js獲取實時日期和時間


//在相應位置顯示時間日期

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM