Date.parse() function in JavaScript

JavascriptWeb DevelopmentFront End Scripts

The Date object is a data type built into the JavaScript language. Date objects are created with the new Date( ) as shown below.

Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.

The parse() function accepts the date in string format and parses it and calculates the total milliseconds since 1st January 1970 and returns it.

Syntax

Its syntax is as follows

Date.parse();

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var dateObj = Date.parse('29 sep 1989 00:4:00 GMT');
      document.write("Number of milliseconds from 1970: "+dateObj);
   </script>
</body>
</html>

Output

Number of milliseconds from 1970: 623030640000

Example

 Live Demo

<html>
<head>
   <title>JavaScript parse Method</title>
</head>
<body>
   <script type="text/javascript">
      var msecs = Date.parse( "Aug 28, 2008 23:30:00" );
      document.write(Date(msecs));
   </script>
</body>
</html>

Output

Wed Oct 17 2018 12:31:35 GMT+0530 (India Standard Time)
raja
Published on 24-Oct-2018 16:50:06
Advertisements