制作时间小程序

分享一个制作日期的小代码

<script type="text/javascript">
			var time = document.getElementById('time');
			setInterval(function() {
				var now = new Date();
				var year = now.getFullYear();
				var month = now.getMonth()+1;
				var date = now.getDate();
				var hours = now.getHours();
				var minutes = now.getMinutes();
				var seconds = now.getSeconds() + "";
	
				if (seconds.length < 2) {
					seconds = "0" + seconds;
				}
	
				time.innerHTML =year+"年" + "-" + month+"月" + "-" + date+"日" + " " + hours + ":" + minutes + ":" + seconds;
			},1000);
	
	
		</script>

猜你喜欢

转载自blog.csdn.net/weixin_43805230/article/details/85330612