动态获取当前日期时间
html
<span class="index_h_c_time">2022年2月11日 17:28:05</span>
js
<script>
function clock(){
now = new Date();
year = now.getFullYear();
month = now.getMonth() + 1;
day = now.getDate();
hour = now.getHours();
min = now.getMinutes();
sec = now.getSeconds();
if (hour < 10) {
hour = "0" + hour;
}
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
$(".index_h_c_time").html(
year + "年" + month + "月" + day + "日" + " " + hour + ":" + min + ":" + sec
);
}
setInterval(clock,1000);
</script>