Chapter 10. Dates and Times

Introduction

Dates and times are important to many ActionScript applications, particularly when you develop more robust applications that offer users services. 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, and for storing transaction dates, to name but a few scenarios.

ActionScript stores dates and times internally as Epoch milliseconds, which are the number of milliseconds that have elapsed since the Epoch, namely midnight, January 1, 1970 Coordinated Universal Time (UTC). For our purposes, UTC is essentially equivalent to the more familiar Greenwich Mean Time (GMT). (See http://aa.usno.navy.mil/faq/docs/UT.html to learn about 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, using methods such as getFullYear( ), setFullYear( ), getMonth( ), and setMonth( ). These methods are for your convenience, but the values are stored internally as Epoch milliseconds.

Get Actionscript 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.