JS实现简单的显示时间

    xiaoxiao2024-12-19  4

    通过JS实现在页面中显示当前的时间和显示停留在页面的时间。

    <script type="text/javascript"> function time() { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth()+1; var day = date.getDate(); var house = date.getHours(); var minutes = date.getMinutes(); var second = date.getSeconds(); var milsecond = date.getMilliseconds(); document.getElementById("showtime").innerHTML = year + "-" + month + "-" + day + " " + house + ":" + minutes + ":" + second + ":" + milsecond; setTimeout("time()", 100); } var timestart = new Date(); function overtime() { var tt = new Date(); var ttt = new Date(tt.getTime() - timestart.getTime()); var milsecond1 = ttt.getMilliseconds(); var second1 = ttt.getSeconds(); var minutes1 = ttt.getMinutes(); document.getElementById("showtime1").innerHTML =minutes1+"分"+":"+second1+"秒"+":"+milsecond1+"毫秒"; setTimeout("overtime()", 100); } </script>

    <body οnlοad="time(),overtime()"> <div class="top"> <font>系统当前的时间:</font> <font id="showtime"></font><br> <font>页面停留的时间:</font> <font id="showtime1"></font> </div> </body> 运行结果:

    转载请注明原文地址: https://ju.6miu.com/read-1294753.html
    最新回复(0)