JavaScript Program to Convert Date to Number Last Updated : 16 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like 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() MethodThis 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()); Output1702449453367 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()); Using the Unary Plus Operator (+)You can also convert a Date object to a Number using the unary plus operator (+). When applied to a Date object, it coerces the Date object into its equivalent numeric value, which represents the number of milliseconds since the epoch (January 1, 1970). JavaScript // JavaScript Program to Convert Date to Number const date = new Date('May 19, 2000 12:10:52'); console.log(+date); Output958738252000 Comment More infoAdvertise with us Next Article Java DateFormat getInstance() Method with Examples H harshil99 Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2022 javascript-date JavaScript-Questions +2 More Similar Reads Convert string into date using JavaScript In this article, we will convert a string into a date using JavaScript. A string must follow the pattern so that it can be converted into a date. A string can be converted into a date in JavaScript through the following ways: Table of Content Using JavaScript Date() constructorUsing JavaScript toDat 3 min read JavaScript Date UTC() Method In JavaScript, the Date.UTC() method is used to create a date object representing a specified date and time in UTC (Coordinated Universal Time). It accepts the year, month, day, hour, minute, second, and millisecond components of the date and returns the number of milliseconds since January 1, 1970, 4 min read How to Convert String to Date Time in Scala? In this article, we will learn how to convert String to DateTime in Scala. Converting String to DateTime consists of parsing a textual representation of date and time into a structured DateTime object for further manipulation and processing in Scala programs. Table of Content Using SimpleDateFormatU 4 min read JavaScript Date Programming Examples The JavaScript comes with a built-in datatype called the Date object. The Date object is created by using a new keyword, i.e. new Date() . The Date object can be used for date and time in terms of millisecond precision within 100 million days before or after 1/1/1970. JavaScript Date Programming Exa 5 min read Java DateFormat getInstance() Method with Examples The getInstance() method of DateFormat class will return the date and time formatter with the default formatting style for the default locale. Syntax: public static final DateFormat getInstance() Parameter: This method doesn't require any parameters. Return value: This method will return the date fo 2 min read Compare Dates in Java The Date class represents a specific instant in time, with millisecond precision. The Date class of java.util package implements Serializable, Cloneable and Comparable interface. It provides constructors and methods to deal with date and time with java. The following are the methods to compare dates 3 min read Like