The Wayback Machine - https://web.archive.org/web/20231213133344/https://www.geeksforgeeks.org/javascript-date-now-method/
Open In App
Related Articles

JavaScript Date now() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

JavaScript 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:

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

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

Javascript




// Use of method Date.now()
let 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: 1702447051020

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

Javascript




// Use of Date.now() method
let 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: Wed Dec 13 2023 05:57:31 GMT+0000 (Coordinated Universal 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
let 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: Wed Dec 13 2023 05:57:31 GMT+0000 (Coordinated Universal Time)

Supported Browsers

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

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


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 13 Dec, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials