实现计时、时钟,实时获取当前年月日时分秒,记录时间(获取_javascript

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>现在时刻</title>
</head>
<body>
<div id="now"></div>
</body>
<script>
/*实现计时,记录时间(获取当前的时间,开始计时,计时过程相当于你的电脑时钟)0000年00月00日 00:00:00*/
function now(id) {
let div = document.getElementById(id);
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();
month = month < 10 ? "0" + month : month;
day = day < 10 ? "0" + day : day;
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
div.innerHTML = "现在时间:" + year + "年" + month + "月" + day + "日" + " " + hours + ":" + minutes + ":" + seconds;/* div.innerHTML = "现在时间:" + year + "年" + month + "月" + day + "日" + " " + hours + "时" + minutes + "分" + seconds + "秒";*/
}

now("now"), setInterval("now('now')", 1000);
</script>
</html>