How to use parse in JavaScript

In this article, I will explain use of parse() method in JavaScript date object.
  • 1970

JavaScript Date Object

  • Date object is used to work with dates and times.

  • Date objects are created with new Date().

JavaScript parse() method

parse() method takes a date string and returns the number of milliseconds between the date string and midnight of January 1, 1970.

Syntax

Date.parse(stringDate)

  • stringDate stringDate is required. A string representing a date.

Example

In the following example show to parse() method converts the string representation of the date.

<!DOCTYPE html>

<html>

<body>

<h3 style="color:ThreeDDarkShadow">JavaScript parse() Method Example</h3>

<p id="demo">Click for display milliseconds between a given date and January 1, 1970.</p>

<button onclick="myFunction()">Click On</button>

<script type="text/javascript">

    function myFunction() {

        var d = Date.parse("July 12, 2012");

        var x = document.getElementById("demo");

        x.innerHTML = "Milliseconds is :" + d;

    }

</script>

</body>

</html>

Output1

parse.jpg

Output2

parse 2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.