The method is very simple and the code is also very concise. Just provide the code
js gets the current time and displays it on the page
<script><br>
window.onload=function(){<br>
//The timer calls fnDate()<br> once every second
setInterval(function(){<br>
fnDate();<br>
},1000);<br>
}<br>
//js gets the current time <br>
function fnDate(){<br>
var oDiv=document.getElementById("div1");<br>
var date=new Date();<br>
var year=date.getFullYear();//Current year<br>
var month=date.getMonth();//Current month<br>
var data=date.getDate();//day<br>
var hours=date.getHours();//Hours<br>
var minute=date.getMinutes();//minutes<br>
var second=date.getSeconds();//seconds<br>
var time=year "-" fnW((month 1)) "-" fnW(data) " " fnW(hours) ":" fnW(minute) ":" fnW(second);<br>
oDiv.innerHTML=time;<br>
}<br>
//Fill in 0 when a field is not a two-digit number <br>
function fnW(str){<br>
var num;<br>
str>10?num=str:num="0" str;<br>
return num;<br>
} <br>
</script>