Copy the code code as follows:
<html>
<head>
<title></title>
<script>
function getDateDemo(){
/*
//Declaration time
var date = new Date();
alert(date);//current time
alert(date.toLocaleString());//Convert to local time
alert(date.getFullYear());//Display the year
alert(date.getMonth() + 1);//Display month 0-11, need to add 1
alert(date.getDate());//Display the date in January
alert(date.getDay());//Display the date and day of the week
alert(date.getHours());//Get the hour time
alert(date.getMinutes());//Get the current minutes
alert(date.getSeconds());//Get the current seconds
alert(date.getMilliseconds());//Get the current number of milliseconds
alert(date.getTime());//Get the millisecond value from midnight on January 1, 1970 to the current time
*/
//Get the year, month, day, hour, minute and second respectively
var myDate = new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth() + 1;
var date = myDate.getDate();
var hours = myDate.getHours();
var minutes = myDate.getMinutes();
var seconds = myDate.getSeconds();
//The month is displayed as two digits, such as September
if(month < 10){
month = "0" + month;
}
if(date < 10 ){
date = "0" + date;
}
//Time splicing
var dateTime = year + "year" + month + "month" + date + "day" + hours + "hour" + minutes + "minute" + seconds + "second";
//document.write(dateTime);//Print the current time
var divNode = document.getElementById("time");
divNode.innerHTML = dateTime;
}
window.setInterval("getDateDemo()",1000);//Every second, call getDateDemo()
</script>
</head>
<body>
<div id="time"></div>
</body>
</html>