Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Date now() Method

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 02 Jan, 2023
Improve Article
Save Article

In this article, we will learn about the Date now() method in Javascript. The date.now() method is used to return the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. Since now() is a static method of Date, it will always be used as Date.now(). 

Syntax:

var A = Date.now();

Parameters: This method does not accept any parameter. 

Return Values: It returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.

Please refer to the JavaScript Get Date Methods article for other Date methods in detail.

More codes for the above method are as follows: 

Example 1: The below example illustrates the Date now() method.

Javascript




// Use of method Date.now()
var A = Date.now();
  
// Printing the number of millisecond elapsed 
console.log("The time elapsed in millisecond is: " + A);

Output:

The time elapsed in millisecond is: 1529644667834

Example 2: This example illustrates getting the current date using the Date.now() method.

Javascript




// Use of Date.now() method
var d = Date(Date.now());
  
// Converting the number of millisecond 
// in date string
a = d.toString()
  
// Printing the current date                    
console.log("The current date is: " + a)

Output:

The current date is: Fri Jun 22 2018 10:54:33 
GMT+0530 (India Standard Time)

Example 3: The Date(Date.now()) is the same as Date(), so the same result can be achieved i.e, the current date using the following code.

Javascript




// Using Date() method
var d = Date();
  
// Converting the number value to string
a = d.toString() 
  
// Printing the current date
console.log("The current date is: " + a)

Output:

The current date is: Fri Jun 22 2018 11:02:01 
GMT+0530 (India Standard Time)

We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete reference article.

Supported Browsers: The browsers supported by JavaScript Date now() method are listed below:

  • Google Chrome
  • Internet Explorer
  • Mozilla Firefox
  • Opera
  • Safari

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!