我创建了一个用于显示日历的小脚本,但月份是一位数字。 EG June 显示 5 而不是 6。
看这里:http://jsfiddle.net/jwoodcreative/vgTN7/
我做错了什么......?
最佳答案
在 JavaScript 中,月份从 0 开始。只需向其添加 1。来自MDN article (强调):
The value returned by
getMonth
is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.
这是在 ECMAScript specification 中定义的:
Months are identified by an integer in the range 0 to 11, inclusive.
这是一个 updated fiddle .
关于javascript 日期问题 - 0 变成 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10960388/