Skip to content

Latest commit

 

History

History
63 lines (52 loc) · 2.2 KB

File metadata and controls

63 lines (52 loc) · 2.2 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
Date.now Function (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
JavaScript
TypeScript
DHTML
now method
41beda89-1a40-4fb1-88b0-38c090af739b
14
mikejo5000
mikejo
ghogen

Date.now Function (JavaScript)

Gets the current date and time.

Syntax

  
Date.now()  

Return Value

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

Remarks

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).

Example

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>  

Requirements

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 [!INCLUDEwin8_appname_long] apps.

See Also

getTime Method (Date)
Date Object
Calculating Dates and Times (JavaScript)
JavaScript Methods