1 <!-- 參考教程:https://www.cnblogs.com/carekee/articles/1678041.html --> 2 <div id="time"></div> 3 <script> 4 time(); 5 setInterval(time,1000) 6 function ...
1 <!-- 參考教程:https://www.cnblogs.com/carekee/articles/1678041.html --> 2 <div id="time"></div> 3 <script> 4 time(); 5 setInterval(time,1000) 6 function time() { 7 var t = new Date(); 8 var y = t.getFullYear(), 9 m = t.getMonth() + 1, 10 d = t.getDate(), 11 h = t.getHours(), 12 min = t.getMinutes(), 13 s = t.getSeconds(); 14 if( y < 10 ){ y = '0' + y } 15 if( d < 10 ){ d = '0' + d } 16 if( h < 10 ){ h = '0' + h } 17 if( min < 10 ){ min = '0' + min } 18 if( s < 10 ){ s = '0' + s } 19 var full_time = y + '-' + m + '-' + d + ' ' + h + ':' + min + ':' + s; 20 document.getElementById('time').innerText = full_time; 21 } 22 </script>