javascript中使用getMonth()获得月份比实际月份少一个月

今天学习js时发现使用getMonth()获得月份比实际月份少一个月

<!DOCTYPE html>
<html>
<head>
	<title>month</title>
	<script type="text/javascript">
	var time =new Date();
	document.write("现在是:2019年"+time.getMonth()+"月"+time.getDate()+"日");
	</script>
</head>
<body>

</body>
</html>

在这里插入图片描述

显然不对,当前时间为2019年10月28日

一番研究,发现通过getDate()获取的月份是0-11 ,所以+1就对了。
发布了34 篇原创文章 · 获赞 3 · 访问量 985

猜你喜欢

转载自blog.csdn.net/qq_41870790/article/details/102787206