Home >>JavaScript Date Object Methods >JavaScript Date parse() Method

JavaScript Date parse() Method

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 Values

Parameter Description
datestring This is a required parameter. It defines a string representing a date.

Browser Support

Method Chrome Edge Firefox Safari Opera
parse() Yes Yes Yes Yes Yes
Here is an example of JavaScript parse() method:
<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>
Output:

Click the button to see the Output.

Example 2:
<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>
Output:

Click the button to see the Output.


No Sidebar ads