Date.UTC( ) Class Method | Flash 5 |
retrieve the number of milliseconds between January 1, 1970 and a supplied UTC date |
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.
The number of milliseconds between the specified date and midnight, January 1, 1970.
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.
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
Date( ), Date.setTime( ), the Date class