In this video, we will write a JavaScript Program to Convert a Date into a Number.
Here we see 2 Java script methods for converting date into numbers.
Method - 1 Date.getTime( ):
In first method we use Javascript Date.getTime() function. When the getTime() method is called on this date object it will return the number of milliseconds. The getTime() always uses UTC to represent a time.
Method - 2 Date.parse( ):
The Date.parse() method parses a string representation of a date and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2022-07-31).
Algorithm:
Step 1: Create an object.
Step 2: Use Date.parse() or Date.getTime()
Step 3: Display output
Javascript date format programs:
https://www.geeksforgeeks.org/javascript-date-formats/
https://www.geeksforgeeks.org/javascript-date/
https://www.geeksforgeeks.org/javascript-get-date-methods/