为什么是Date()。dateUTC的第一个索引1和Date()。monthUTC的第一个索引为0? [英] Why is Date().dateUTC's first index 1 and Date().monthUTC's first index 0?

查看:146
本文介绍了为什么是Date()。dateUTC的第一个索引1和Date()。monthUTC的第一个索引为0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Actionscript 3中,dateUTC和monthUTC具有不同的索引范围。

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

使用2015年10月12日的日期,UTC日期变量日期

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

dateUTC 的范围是1-31。

The range for dateUTC is 1-31.

monthUTC 的范围是0-11

为什么dateUTC从1开始,monthUTC从0开始?

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

推荐答案

还有一个逻辑背后,日子是真正的数字而几个月没有。日历是指带有数字的日期,并将月份表示为字符串。你永远不会听到第4个例子,但你会听到第6天的例子。由于AS3 Date不提供月份名称,它只提供从0到11的索引,因为日期是数字Date从1到n正确地提供它们。这里还有另一种背后的逻辑,语言。日期中没有提供名称(如月份名称),因为支持所有语言将会很痛苦。相反,您使用月份索引以任何语言显示月份(您编码器提供的月份),另一方面天数不需要,因为它们是数字。

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.

在大多数语言中,您将看到类似的模式,因为提供月份名称很麻烦,因此您可能会从0到11获得索引。

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.

这篇关于为什么是Date()。dateUTC的第一个索引1和Date()。monthUTC的第一个索引为0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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