<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>时间</title>
</head>
<body>
<span id="mytime"></span>
<script>
function showTime(){
nowtime = new Date();//
year = nowtime.getFullYear();//获取当前完整的年份
month = nowtime.getMonth()+1;//获取当前月份
date = nowtime.getDate();//获取当前日
document.getElementById("mytime").innerText = year+"年"+month+"月"+date+"日"+nowtime.toLocaleTimeString();//toLocaleTimeString()根据本地时间把 Date 对象的时间部分转换为字符串
}
function showTime2(){
document.getElementById("mytime").innerText = new Date();
}
setInterval('showTime()',1000);//1秒更新一次
</script>
</body>
</html>
用JS编程出动态显示当前系统的时间日期信息
最新推荐文章于 2024-08-06 23:12:50 发布
本文介绍如何利用JavaScript编程实现网页上动态更新当前系统的日期和时间信息,为用户提供即时的时间显示功能。
摘要由CSDN通过智能技术生成