Date.getTime( ) Method

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

retrieve the number of milliseconds between January 1, 1970 and the time of a Date object
date.getTime()

Returns

An integer expressing the number of milliseconds between the time of date and midnight, January 1, 1970 positive if after January 1, 1970; negative if before.

Description

Internally, all dates are represented as a single number the number of milliseconds between the time of the date and midnight, January 1, 1970. The getTime( ) method gives us access to that number of milliseconds so that we can use it to construct other dates or calculate the elapsed time between two dates.

Example

Suppose we place the following code on frame 10 of a movie:

time1 = new Date();

Then we place the following code on frame 20 of a movie:

time2 = new Date();

With the following code, we can determine the amount of time that elapsed, in milliseconds, between frames 10 and 20 of our movie:

elapsedTime = time2.getTime() - time1.getTime();

Note that Flash's global getTimer( ) function also gives us access to elapsed time in a movie.

See Also

Date.setTime( ), getTimer( ), setInterval( )



    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