Name

Date.UTC( ) Class Method — retrieve the number of milliseconds between January 1, 1970 and a supplied UTC date

Availability

Flash 5

Synopsis

Date.UTC(year, month, day, hours, minutes, seconds, ms)

Arguments

year,...ms

A series of numeric values describing the date and time but supplied in UTC time, not local time. For descriptions of each argument see the Date( ) constructor.

Returns

The number of milliseconds between the specified date and midnight, January 1, 1970.

Description

The Date.UTC( ) method takes the same arguments as the Date( ) constructor, but instead of returning an object for the specified date, Date.UTC( ) returns a number indicating the date in the internal milliseconds-from-1970 format. The returned number is typically used to construct a new Date object in UTC or to assign a UTC time to an existing Date object via the setTime( ) method.

Example

The following code shows how to measure the milliseconds elapsed between midnight 1970 and midnight 2000 in UTC time:

trace(Date.UTC(2000, 0) + " milliseconds passed between 1970 and 2000.");
// Displays: "946684800000 milliseconds passed between 1970 and 2000."

Here we use those elapsed milliseconds to construct a UTC-time-based Date object:

nowUTC = new Date(Date.UTC(2000, 0));

If that code were invoked in EST (Eastern Standard Time), which is 5 hours behind UTC, nowUTC would represent the local time 7p.m. on December 31, 1999. When we check the hour using the non-UTC method getHours( ), we get the local hour, 19 (7p.m. in a 24-hour ...

Get ActionScript: The Definitive Guide 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.