Javascript Date.parse() 结果为 NaN

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11516332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 06:07:27  来源:igfitidea点击:

Date.parse() results in NaN

javascriptjquerydate

提问by sozhen

Date.parse();

My jsFiddleworks fine, but run it in my ide (both Aptana and WebStorm) shows NaNin the console.log()output.

我的jsFiddle工作正常,但在我的 ide(Aptana 和 WebStorm)中运行它显示NaNconsole.log()输出中。

Really confused about this... Has someone had such experience before?

真的很困惑这个……以前有人有过这样的经历吗?

回答by Tats_innit

Working demohttp://jsfiddle.net/7KfuM/

工作演示http://jsfiddle.net/7KfuM/

Change -to /

更改-/

Good read: Jquery Date.parse returning NaN in Chrome browser?orhttps://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

好读:Jquery Date.parse 在 Chrome 浏览器中返回 NaN?https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

Try this:

尝试这个:

var firstDayTimestamp = Date.parse("2009/07/13 00:00:00" + "-0500") / 1000;

Hope this fits the cause! B-)

希望这符合原因! B-)

回答by Picard

The date should be in the IETF date syntax (RFC2822 Section 3.3) format, e.g. "Mon, 25 Dec 1995 13:30:00 GMT", or "Mon, 25 Dec 1995 13:30:00 GMT+0430".

日期应采用 IETF 日期语法(RFC2822 第 3.3 节)格式,例如“Mon, 25 Dec 1995 13:30:00 GMT”或“Mon, 25 Dec 1995 13:30:00 GMT+0430”。

Read more: Date.parse()

阅读更多:Date.parse()

Surprisingly this should be done also for the current (2017) versions of IE (11.x) and FF (56.x) for the Date.parse to work correctly.

令人惊讶的是,对于当前(2017)版本的 IE (11.x) 和 FF (56.x) 也应该这样做,以便 Date.parse 正常工作。