英文:
Incorrect date returned
问题
手动输入日期时为什么会返回错误的日期给我,而通过日历选择日期则一切正常?
const newDate = new Date(2022, 10, 10);
期望返回十月10日,但返回的是2022年11月9日。
英文:
Tell. Why is the wrong date returned to me when MANUALly entering the date in new Date()?
If you choose through the calendar, then everything works
const newDate = new Date(2022,10,10)
Expected to return October 10, but is returning 2022-11-09
答案1
得分: 4
月份从0开始,与其他不同。十月的月份索引为9。
const date = new Date(2022,9,10)
0  -> 一月
1  -> 二月
2  -> 三月
3  -> 四月
4  -> 五月
5  -> 六月
6  -> 七月
7  -> 八月
8  -> 九月
9  -> 十月
10 -> 十一月
11 -> 十二月
希望这对您有帮助!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论