Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...