Definition and Usage
The parse() method parses a date and time string and returns the number of milliseconds from midnight on January 1, 1970 to the date and time.
Syntax
Date.parse(datestring)
Parameters | Description |
datestring | Required. A string representing the date and time. |
Return value
The number of milliseconds between the specified date and time as of midnight (GMT time) on January 1, 1970.
Description
This method is a static method of the Date object. This method is generally called in the form of Date.parse() instead of dateobject.parse().
Tips and Notes:
Note: Date.parse() is a static method of the Date object.
Example
Example 1
In this example, we will get the number of milliseconds from 1970/01/01 to 2005/07/08:
<script type="text/javascript"> var d = Date.parse("Jul 8, 2005") document.write(d) </script>
Output:
1120752000000
Example 2
Now, we will convert the output of the above example into adults:
<script type="text/javascript"> var minutes = 1000 * 60 var hours = minutes * 60 var days = hours * 24 var years = days * 365 var t = Date.parse("Jul 8, 2005") var y = t/years document.write("It's been: " + y + " years from 1970/01/01") document.write(" to 2005/07/08!") </script>
Output:
It's been: 35.538812785388124 years from 1970/01/01 to 2005/07/08!
The following are the details of the parameters:
datestring : 一个字符串,表示日期
Return value:
The number of milliseconds since midnight on January 1, 1970.
Example:
<html> <head> <title>JavaScript parse Method</title> </head> <body> <script type="text/javascript"> var msecs = Date.parse("Jul 8, 2008"); document.write( "Number of milliseconds from 1970: " + msecs ); </script> </body> </html>
This will produce the following results:
Number of milliseconds from 1970: 1215455400000
The above is the detailed content of JavaScript method parse() based on the date and time according to the number of milliseconds between 1970/1/1 midnight (GMT time). For more information, please follow other related articles on the PHP Chinese website!