javascript動態擷取登入時間和線上時間長度_javascript技巧

來源:互聯網
上載者:User

本文執行個體介紹了javascript動態擷取登入時間和線上時間長度的相應代碼,分享給大家供大家參考,具體內容如下

效果圖:

實現代碼:

<html> <head> <title>online</title> <script language=javaScript> ///這裡是獲得登入時候的時間,用來和動態時間做差來求時間長度 var s = new Date(); function clockon() { var thistime = new Date(); //時間差 diff = new Date(); diff.setTime(Math.abs(thistime.getTime() - s.getTime())); timediff = diff.getTime(); hos = Math.floor(timediff / (1000 * 60 * 60)); mins = Math.floor(timediff / (1000 * 60)); secs = Math.floor(timediff / 1000); //end var hours = thistime.getHours(); var minutes = thistime.getMinutes(); var seconds = thistime.getSeconds(); if (eval(hours) < 10) {  hours = "0" + hours; } if (eval(minutes) < 10) {  minutes = "0" + minutes; } if (seconds < 10) {  seconds = "0" + seconds; } thistime = hours + ":" + minutes + ":" + seconds; bgclockshade.innerHTML = thistime//這裡動態嵌入當前的時間 //如果不取餘的話,秒數是一直上升的,所以在達到一個60的時候就取餘就可以解決這個問題了 if (secs > 59) {  secs = secs % 60; } if (mins > 59) {  mins = mins % 60; } if (eval(secs) < 10) {  secs = "0" + secs; } if (eval(mins) < 10) {  mins = "0" + mins; } if (eval(hos) < 10) {  hos = "0" + hos; } jishi.innerHTML = hos + ":" + mins + ":" + secs; var timer = setTimeout("clockon()", 200); }</script> </head> <body onload="clockon();"> 登入時間: <div id="bgclockshade"></div> 上網時間長度: <div id="jishi"></div> </body></html>

以上就是本文的全部內容,希望對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.