Open In App

JavaScript Program to Convert Date to Number

Last Updated : 13 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This article will explain how to convert a Date into a Number using JavaScript. The JavaScript Date object is used to get dates and times. It helps in formatting the dates. We can use the new keyword to create an object for Date. To convert a Date to a Number, we use the getTime() method.

getTime() Method

This method returns the number of milliseconds since midnight of January 1, 1970 (epoch) to the current date or specified date.

Syntax:

Date.getTime();

Example 1: This example demonstrates how to convert the current Date to a Number.

Javascript




// JavaScript Program to
// Convert Date to Number
 
const date = new Date();
console.log(date.getTime());


Output

1702449453367

Example 2: This example demonstrates how to convert a specified Date to a Number.

Javascript




// JavaScript Program to Convert Date to Number
 
const date = new Date('May 19, 2000 12:10:52');
console.log(date.getTime());


Output

958738252000

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads