Date.UTC( ) Class Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Date.UTC( ) Class Method Flash 5

retrieve the number of milliseconds between January 1, 1970 and a supplied UTC date
date.UTC(year, month, day, hours, minutes, seconds, ms)

Arguments

year, ...ms

A series of numeric values describing the date and time, 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 time 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, January 1, 1970 and midnight, January 1, 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 we invoke that code in EST (Eastern Standard Time), which is 5 hours behind UTC, nowUTC represents the local time, 7 P.M. on December 31, 1999. When we check the hour using the non-UTC method getHours( ), we get the local hour, 19 (7 P.M. in a 24-hour clock):

trace(nowUTC.getHours());  // Displays: 19

But when we check the hour using the UTC method getUTCHours( ), we get the correct UTC hour, (midnight in a 24-hour clock):

trace(nowUTC.getUTCHours());  // Displays: 0

See Also

Date( ), Date.setTime( ), the Date class



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net