Open In App

JavaScript Date now() Method

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

The Date.now() method in JavaScript returns the current timestamp in milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC). Date.now() is a static method of the Date object.

Date now() Method Syntax

let A = Date.now();

Date now() Method Parameters

This method does not accept any parameter. 

Date now() Method Return Values

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

Date now() Method Example

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


Explanation

The code snippet utilizes `Date.now()` to retrieve the current timestamp in milliseconds since the Unix epoch. It stores this value in variable `A` and prints it, indicating the elapsed milliseconds since the epoch.

Date now() Method Example:

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)


Explanation

The code snippet generates a new `Date` object using the current timestamp from `Date.now()`. It then converts this date object to a string format using `.toString()` and logs it, displaying the current date and time.

Date now() Method UseCases

1. JavaScript Get Date Methods

JavaScript `getDate()` method retrieves the day of the month (1-31) from a Date object. It doesn’t require any parameters and returns the numeric value representing the day of the month.

2. How to Log the Current Date in JavaScript ?

 To log the current date in JavaScript, create a new Date object and call its toDateString() method, or use console.log(new Date().toDateString()).

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

Supported Browsers



Last Updated : 05 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads