7

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

 3 years ago
source link: https://blog.csdn.net/qq_48965298/article/details/112134821
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

置顶 prime_zxx 2021-01-03 14:41:50 2492
<!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>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK