User Guide
Managing calendar dates and times 199
■ The day property, which is the day of the week in numeric format, with 0 standing for
Sunday
■ The hours property, in the range of 0 to 23
■ The minutes property
■ The seconds property
■ The milliseconds property
In fact, the Date class gives you a number of ways to get each of these values. For example, you
can get the month value of a Date object in four different ways:
■ The month property
■ The getMonth() method
■ The monthUTC property
■ The getMonthUTC() method
All four ways are essentially equivalent in terms of efficiency, so you can use whichever
approach suits your application best.
The properties just listed all represent components of the total date value. For example, the
milliseconds property will never be greater than 999, since when it reaches 1000 the seconds
value increases by 1 and the milliseconds property resets to 0.
If you want to get the value of the Date object in terms of milliseconds since January 1, 1970
(UTC), you can use the
getTime() method. Its counterpart, the setTime() method, lets you
change the value of an existing Date object using milliseconds since January 1, 1970 (UTC).
Performing date and time arithmetic
You can perform addition and subtraction on dates and times with the Date class. Date values
are kept internally in terms of milliseconds, so you should convert other values to milliseconds
before adding them to or subtracting them from Date objects.
If your application will perform a lot of date and time arithmetic, you might find it useful to
create constants that hold common time unit values in terms of milliseconds, like the
following:
public static const millisecondsPerMinute:int = 1000 * 60;
public static const millisecondsPerHour:int = 1000 * 60 * 60;
public static const millisecondsPerDay:int = 1000 * 60 * 60 * 24;