Chapter 14. Dates and Times
Introduction
Dates and times are important to many ActionScript applications, particularly when more robust applications are developed to offer services to users. For example, date and time values are important for determining the amount of time that has elapsed for timed operations, for determining whether a user’s trial membership is active or about to expire, and for storing transaction dates.
ActionScript stores dates and times internally as epoch milliseconds, the number of milliseconds that have elapsed since the Epoch—midnight, January 1, 1970 Coordinated Universal Time (UTC). For our purposes, UTC is essentially equivalent to the more familiar Greenwich Mean Time (GMT). See the U.S. Naval Observatory’s site (http://aa.usno.navy.mil/faq/docs/UT.html) regarding the subtle distinctions. Many programming languages store dates in terms of the epoch (often in seconds instead of milliseconds); therefore, you can readily work with date and time values that have been imported from other sources (and vice versa).
In addition, the Date class allows you to set and get date and
time values in terms of years, months, days, and so on by using
properties such as fullYear
, month
, etc. These properties are for your
convenience, but the values are stored internally as epoch
milliseconds.
Finding the Current Date and Time
Problem
You want to know the current date and time.
Solution
Create a new date by using the Date() constructor with no parameters. Alternatively, ...
Get ActionScript 3.0 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.