gpt4 book ai didi

javascript - 从日期中提取错误的月份

转载 作者:行者123 更新时间:2023-12-02 17:22:39 27 4
gpt4 key购买 nike

我使用了以下代码:

var date = $('#datefromcal').val();
var dt = new Date(date);
alert(dt); // RESULT= Wed May 21 12:00:00 UTC+0200 2014
alert("Date : " + dt.getDate());//RESULT= Date : 21
alert("Month : " + dt.getMonth());//RESULT= Month : 4
alert("Year : " + dt.getFullYear()); //RESULT= Year : 2014

我尝试提取日、月和年。我总是收到月份:4,但现在是五月。我的结果显示在评论中。

有人可以解释一下为什么会发生这种情况吗?或者如何提取月份。

谢谢

最佳答案

The getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year).

The value returned by getMonth is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.

关于javascript - 从日期中提取错误的月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23788657/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com