User Guide

197
6
CHAPTER 6
Working with Dates and
Times
Timing might not be everything, but it's usually a key factor in software applications.
ActionScript 3.0 provides powerful ways to manage calendar dates, times, and time intervals.
Two main classes provide most of this timing functionality: the Date class and the new Timer
class in the flash.utils package.
Contents
Managing calendar dates and times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Controlling time intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Example: Simple analog clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Managing calendar dates and times
All of the calendar date and time management functions in ActionScript 3.0 are concentrated
in the top-level Date class. The Date class contains methods and properties that let you
handle dates and times in either Coordinated Universal Time (UTC) or in local time specific
to a time zone. UTC is a standard time definition that is essentially the same as Greenwich
Mean Time (GMT).
Creating Date objects
The Date class boasts one of the most versatile constructor methods of all the core classes. You
can invoke it four different ways.
First, if given no parameters, the
Date() constructor returns a Date object containing the
current date and time, in local time based on your time zone. Heres an example:
var now:Date = new Date();