What is Date.now() in Javascript?

In Javascript, the .now() method is a Date static method that returns the number of milliseconds since January 1, 1970 00:00:00 UTC. This date is also known as the UNIX epoch.

Syntax

Date.now()

Parameters

There are no parameters.

Return Value

The Date.now() method returns a number that represents the milliseconds that have passed since the UNIX epoch up until now.

Example

In the example below, we can see the use of the Date.now() method and logout the returned value to the console.

// use the Date.now() method
let date = Date.now()
// log returned value to console
console.log(date);

Note: The returned value of the Date.now() can be passed to a date object.

In the code below, we use the returned milliseconds of Date.now() as a parameter to a date object. Next, we format the date object to an interpretable format.

// use the Date.now() method
let date = Date.now()
// use milliseconds in a date object
let currentDate = new Date(date)
// log milliseconds value to console
console.log(date);
// format the date object
console.log("Current time is :" +currentDate.toString());

Free Resources