The JavaScript date now() function is a static method available in the Date object. The Date.now() function returns the total number of milliseconds elapsed since 01-01-190 00:00:00 UTC to the given date. This article shows you how to use Date.Now with an example.
The following example helps you understand the now Function. The syntax of the Date now function is
Date.now()
What does Date.now() return in JavaScript?
The Date.now() function returns the total number of milliseconds between January 01, 1970 00:00:00, and the current or given date and time.
In the following example, we use the Date.now() function to find the time in milliseconds elapsed from January 1970 to the current date and time.
const dt = Date.now();
console.log(dt);
As you can see, it is returning the current timestamp in milliseconds.
1781240758948
How to get current timestamp in JavaScript?
The simplest way to obtain the current timestamp is by using the Date.now() function.
console.log(Date.now());
1781240758948
Convert milliseconds to Date and time
In the following example, we use the built-in Date() method to convert milliseconds returned by the Date.now() function to an actual date and time. For this JScript example, you have to use the Date Function.
const dt = Date(Date.now());
console.log(dt);
Fri Jun 12 2026 10:37:00 GMT+0530 (India Standard Time)
JavaScript date now get year
As it is not possible to extract the year part from the milliseconds, we must convert milliseconds to a date. First, use the new Date() function to convert milliseconds to a Date object of the current date and time. Next, use the getFullYear() method to extract the year number in yyyy format.
const dt = new Date(Date.now());
let year = dt.getFullYear();
console.log(year);
2026
The other option is using the new Date() object and applying the getFullYear() function on it.
const dt = new Date().getFullYear();
console.log(dt);
2026
JavaScript date now to string
There are multiple options to convert the milliseconds returned by Date.now() to a string. If you intend to convert milliseconds to a string data type, use the toString() method.
const dt = Date.now().toString();
console.log(dt);
1781240758948
However, if you intend to show the date.now() result in a human-readable format of the current date and time, use the below technique. It converts milliseconds to a Date object and then uses the toString() function to convert the current date and time to a string.
const dt = new Date(Date.now());
console.log(dt.toString());
Fri Jun 12 2026 10:46:12 GMT+0530 (India Standard Time)
JavaScript date now in seconds
As we all know, the Date.now() function returns milliseconds. To convert the Date.now() milliseconds to seconds, we must divide the result by 1000. Next, apply the Math floor() function to round down the result.
const dt = Date.now();
let s = Math.floor(dt /1000);
console.log(dt);
1781257491498
JavaScript date now format yyyy mm dd
To format the milliseconds result of the date.now() function, we must use the toISOString() function and apply the slicing technique. The toISOString() function returns the date yyyy-mm-dd hh:mm:ss. So, we must slice the string length to 10.
const dt = new Date(Date.now())
let fd = dt.toISOString().slice(0, 10);
console.log(fd);
2026-06-12
What is the difference between JavaScript Date.now() and new Date().getTime()?
Both the date.now() and the new date().getTime() methods return elapsed milliseconds since 01-01-1970 to the current date and time.
- Date.now(): It is a direct method for returning the current timestamp (milliseconds). It does not require creating a new Date object and applying another method. It is faster and preferable to get the current timestamp.
- new date().GetTime(): First, the new Date() creates a Date object. Next, the getTime() extracts the current timestamp from that object. It is slower compared to date.now().
If your task is to return the current timestamp, use Date.Now(). However, to use the custom date and time, prefer new Date().getTime().
console.log(Date.now());
console.log(new Date().getTime());
console.log(new Date('2020-01-01').getTime());
1781242587604
1781242587610
1577836800000
The following example helps you understand both the now(), and Date() function. As we said earlier, both these function returns the same result.
var dt1 = Date(Date.now());
console.log("Date and Time : " + dt1);
var dt2 = Date();
console.log("Date and Time : " + dt2);
Date and Time : Fri Jun 12 2026 15:17:42 GMT+0530 (India Standard Time)
Date and Time : Fri Jun 12 2026 15:17:42 GMT+0530 (India Standard Time)