用JS编程出动态显示当前系统的时间日期信息

<!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>

你可能感兴趣的:(javascript,js)