Home >>JavaScript Date Object Methods >JavaScript Date parse() Method
JavaScript Date parse() method is used to parse any given input date string and return the number of milliseconds between the given input date and the midnight of January 1, 1970.
Syntax:Date.parse(datestring)
Parameter | Description |
---|---|
datestring | This is a required parameter. It defines a string representing a date. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
parse() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var d = Date.parse("March 10, 2020"); document.getElementById("demo").innerHTML = d; } </script> </body> </html>
Click the button to see the Output.
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction1()">Try it</button> <p id="demo1"></p> <script> function myFunction1() { var d = Date.parse("March 08, 2020"); var minutes = 1000 * 60; var hours = minutes * 60; var days = hours * 24; var years = days * 365; var y = Math.round(d / years); document.getElementById("demo1").innerHTML = y; } </script> </body> </html>
Click the button to see the Output.