作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用了以下代码:
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/
我是一名优秀的程序员,十分优秀!