Date.parse 的正确日期格式应该是哪种?
嘿伙计们,我不知道我应该为 date.parse() 函数设置的正确日期格式是什么。
我想在这样的函数中使用 mm/dd/yyyy 。
alert("Date: "+Date.parse("11/28/2011"));
//-->Its showing me Date:NaN as output.
我还想知道如果我执行以下代码,我应该得到什么输出:
date = Date.parse('12/31/2011' +' UTC');
var minutes=1000*60;
var hours=minutes*60;
var days=hours*24;
var years=days*365;
var y=date/years;
t 应该给我正好 42 年,但它也给我十进制。是吗?
任何帮助将不胜感激。
谢谢
阿南德
Hey guys, Im having trouble knowing wat is the correct date format i should put for date.parse() function.
I want to use mm/dd/yyyy in the function like this.
alert("Date: "+Date.parse("11/28/2011"));
//-->Its showing me Date:NaN as output.
also I wanted to know what output should I be getting if I do this following code:
date = Date.parse('12/31/2011' +' UTC');
var minutes=1000*60;
var hours=minutes*60;
var days=hours*24;
var years=days*365;
var y=date/years;
t should give me exactly 42 years but its giving me decimal as well. Y so??
Any help will be appreciated guys.
Thanks
Anand
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
国际 (ISO) 标准日期时间格式将始终有效。
2011-12-31
您还可以查看这个和这个
International (ISO) standard date time format will always work.
2011-12-31
You may also look at this and this
为什么它会给你整整 42 年?不要忘记,由于闰年(以及闰秒,如果考虑在内),一年中不存在确切的毫秒数。即使有,您得到的也是 2011 年最后一天的开始,这与 2012 年第一天的开始不同,这可能正是您所想的。
据我所知,支持的确切格式是特定于实现的 - 至少对于 ECMAScript 来说(我意识到它与 JavaScript 不太一样)。
Why would it give you exactly 42 years? Don't forget that there's no such thing as an exact number of milliseconds in a year, due to leap years (and leap seconds, if they're accounted for). Even if there were, you're getting the start of the last day of 2011, which isn't the same as the start of the first day of 2012, which is probably what you were thinking of.
The exact formats supported are implementation-specific as far as I can tell - at least for ECMAScript (which I realise isn't quite the same as JavaScript).