Thursday, September 4, 2025
HomeLanguagesJavascriptJavaScript Program to Convert Date to Number

JavaScript Program to Convert Date to Number

This article will explain how to convert a Date into a Number using JavaScript. The JavaScript Date object is used to get date 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 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




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


Output

1671707932556

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

Javascript




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


Output

958738252000
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS