为什么javascript日期月索引从0开始 [英] why is the javascript date month index 0-based

查看:123
本文介绍了为什么javascript日期月索引从0开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多解释尝试,为什么在当天这样创建它(年和日指数基于0)。这些解释都没有真正有意义。

I have read numerous explanation attempts why this was created like this back in the day (with both year and day index are not being 0-based). None of these explanations really made sense.

对我来说更令人惊讶的是:即使在最新的ECMAScript 2018草案中,这个问题仍然存在。
查看ECMAScript 2018中的日期

What is even more surprising to me: even in the latest ECMAScript 2018 draft, this issue still exists. see dates in ECMAScript 2018

Javascript可能刚刚从Java中获取过这个,但是我不明白为什么它没有被改变,除非实际上正当理由。

Javascript might have just taken this from Java long time ago but I don't see why it is not being changed unless there actually is a proper reason for it.

谢谢&问候,
Marcel

Thanks & regards, Marcel

推荐答案


为什么javascript日期月索引0-based

why is the javascript date month index 0-based

这并不奇怪。一周中的某一天也是0。在这两种情况下,通常希望在数组中查找它们的符号版本(例如, [January,February,...] [星期日,星期一,......] )。数组是从0开始的。到目前为止,JavaScript不是唯一使用基于0的值的语言/运行时。

It's not surprising. The day of the week is also 0-based. In both cases, it's common to want to look up symbolic versions of them in arrays (e.g., ["January", "February", ...], ["Sunday", "Monday", ...]). Arrays are 0-based. JavaScript is by far not the only language/runtime that uses 0-based values for this.


对我来说更令人惊讶的是:甚至在最新的ECMAScript 2018草案中,这个问题仍然存在。

What is even more surprising to me: even in the latest ECMAScript 2018 draft, this issue still exists.

这将是 很多 更令人惊讶的是,如果他们在事实发生22年后改变这种情况,就会炸毁数百万个剧本,尤其是因为它的方式非常合理。他们可以添加一个新的访问者,为你做 +1 ,但是......是的,我不会屏住呼吸。 : - )

It would be much more surprising if they changed this 22 years after the fact, blowing up millions of scripts, esp. as it's perfectly rational the way it is. They could add a new accessor that does the +1 for you, but...yeah, I wouldn't hold my breath. :-)

这些基于1的版本的唯一原因是格式化。 JavaScript根本不处理格式化。 ECMA-402中有 一些格式:ECMAScript® 2016国际化API规范,采用 <的形式code> DateTimeFormat

The only reason for 1-based versions of these is formatting. Formatting isn't handled by JavaScript at all. There is some formatting in ECMA-402: ECMAScript® 2016 Internationalization API Specification, in the form of DateTimeFormat.

这篇关于为什么javascript日期月索引从0开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆