![]() |
VOOZH | about |
The JavaScript Date parse() method parses a date string and returns the number of milliseconds between the date string and midnight of January 1, 1970, UTC. If the argument is an invalid date string, it returns NaN (Not a Number).
Date.parse(datestring);This method accepts a single parameter:
Example 1: Parsing Date String to Milliseconds
The code takes a date string "February 18, 2018, 12:30 PM" and parses it using the Date.parse() method, which returns the number of milliseconds since January 1, 1970. The result is logged to the console.
1518957000000
Example 2: Parsing Invalid Date String
The code attempts to parse an invalid date string "February 48, 2018 12:30 PM" using the Date.parse() method. Since the date is invalid, the method returns NaN (Not a Number), which is logged to the console.
NaN
Note: Once we get the millisecond count between two dates, we can easily find the number of hours, days, months, years, etc by simple maths calculation.
The browsers supported by the JavaScript Date parse() method are listed below: