html实时时间代码格式为年月日 时:分:秒
<!DOCTYPE html>
<html>
<head>
<title>实时时间</title>
<meta charset="utf-8">
<script>
function updateTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var timeStr = year + '.' + month + '.' + day + ' ' + hour + ':' + minute + ':' + second;
document.getElementById("time").innerHTML = timeStr;
}
setInterval(updateTime, 1000);
</script>
</head>
<body>
<h1>实时时间</h1>
<div id="time"></div>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/Cwy 著作权归作者所有。请勿转载和采集!