Date.parse 的正确日期格式应该是哪种?

发布于 2024-10-27 14:21:21 字数 473 浏览 2 评论 0原文

嘿伙计们,我不知道我应该为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风透绣罗衣 2024-11-03 14:21:21

国际 (ISO) 标准日期时间格式将始终有效。 2011-12-31

您还可以查看这个这个

International (ISO) standard date time format will always work. 2011-12-31

You may also look at this and this

愿与i 2024-11-03 14:21:21

为什么它会给你整整 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文