Below is the example of Date parse() method.
// Taking a date string as input.
"February 18, 2018 12:30 PM"
// Calling parse function on input date string.
msec = Date.parse(date);
The date.parse() method is used to know the exact number of milliseconds that have passed since midnight, January 1, 1970, till the date we provide.
Parameters: This method accept a single parameter as metnioned above and described below:
- datestring: This parameter holds the date as a string.
Return Values: It returns an integer value representing the number of a millisecond between midnight January 1, 1970, and the date provided. If by any means, the machine can’t recognize the string or the input string is invalid, it will return “NaN” instead of an integer.
More codes for the above method are as follows:
Program 1: If the input string of date is not correct, it return NaN i.e, not a number.
Program 2: If the input string of date is not correct, it return NaN i.e, not a number.
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.
- Google Chrome
- Internet Explorer
- Mozilla Firefox