Why is Date().dateUTC's first index 1 and Date().monthUTC's first index 0?

天大地大妈咪最大 提交于 2019-12-13 08:57:32

问题


In Actionscript 3, dateUTC and monthUTC have different index ranges.

using the date of October 12th, 2015, UTC date variables in Date

var day:int = new Date().dateUTC
//trace = 12
var month:int = new Date().monthUTC
//trace = 9

The range for dateUTC is 1-31.

The range of monthUTC is 0-11

why does dateUTC start at 1 and monthUTC start at 0?


回答1:


There's a logic behind it as well, days are truly numbers while months are not. Calendars refer to days with number and refers to month as string. You never hear month 4 for example but you do hear day 6 for example. Since AS3 Date does not provide month names it only provides their indexes from 0 to 11, since days are number Date provides them correctly from 1 to n. Here again there's another logic behind it, languages. Names (like month names) are not provided in Date because it would be a pain to support all languages. Instead you use the month indexes to display months in any language (that you the coder provides), on the other hand days don't need that since they are numbers.

You will see a similar pattern in most languages since providing month names is cumbersome so instead you will likely get an index from 0 to 11.




回答2:


Why "in ActionScript 3"? Because it's part of the ECMAScript standard for Date objects. Why in ECMAScript? Probably just because that's what Brendan Eich thought made sense when he came up with Javascript.



来源:https://stackoverflow.com/questions/33087334/why-is-date-dateutcs-first-index-1-and-date-monthutcs-first-index-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!