<p id="time"></p>
<script>
var time = document.getElementById("time")
function show() {
let date = new Date();
let year = date.getFullYear(); //获取当前年份
let mon = date.getMonth() + 1; //获取当前月份
let da = date.getDate(); //获取当前日
let h = date.getHours(); //获取小时
let m = date.getMinutes(); //获取分钟
let s = date.getSeconds(); //获取秒
time.innerText = `${year} ${mon} ${da} ${h}:${m}:${s}`;
//通过html中p标签id为time的获取到时间运行
}
setInterval("show()", 1000);
</script>