Javascript获取的月份和系统不符合

<script type="text/javascript">
function  getClock(){
	var time = new Date();
	var year = time.getFullYear()
	var month = time.getMonth()
	var date = time.getDate()
	var hours = time.getHours()
	var minutes = time.getMinutes()
	var seconds = time.getSeconds()
	alert("系统公告:"+year+"年"+month+"月"+date+"日"+hours+"时"+minutes+"分"+seconds+"秒")
}
 getClock()
/*
@auther:lsir34567
@date:2019-05-04
*/
</script>

获取到的数据
在这在这里插入图片描述里插入图片描述

实际系统时间
在这里插入图片描述

总结:getMonth() 方法返回表示月份的数字,返回值是 0-11 之间的一个整数,所以在输出时需要+1才能输出当前的月份

发布了35 篇原创文章 · 获赞 30 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43792401/article/details/100537140