Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Date.now Function (JavaScript)

Gets the current date and time.

Date.now()

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

The getTime method returns the number of milliseconds between January 1, 1970, and a specified date.

For information about how to calculate elapsed time and compare dates, see Calculating Dates and Times (JavaScript).

The following example illustrates the use of the now method.

var start = Date.now();
var response = prompt("What is your name?", "");
var end = Date.now();
var elapsed = (end - start) / 1000;
document.write("You took " + elapsed + " seconds" + " to type: " + response);

// Output:
// You took <seconds> seconds to type: <name>

Not supported in installed versions earlier than Internet Explorer 9. However, it is supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Also supported in Windows Store apps.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft