JavaScript Date parse() method
- Föregående sida nu()
- Nästa sida prototype
- Gå tillbaka till föregående nivå JavaScript Date Referens manual
Definition and usage
parse()
This method parses a date string and returns the number of milliseconds between the date string and midnight on January 1, 1970.
Description
This is a static method of the Date object. It is generally called in the form of Date.parse(), rather than through dateobject.parse() to call this method.
Example
Example 1
Returns the number of milliseconds between January 1, 1970 and March 21, 2012:
var d = Date.parse("March 21, 2012");
Example 2
Calculate the number of years between January 1, 1970 and March 21, 2012:
var d = Date.parse("March 21, 2012"); var minutes = 1000 * 60; var hours = minutes * 60; var days = hours * 24; var years = days * 365; var y = Math.round(d / years);
Syntax
Date.parse(datestring)
Parameter
Parameter | Description |
---|---|
datestring | Required. A string representing the date. |
Technical details
Return value: | A number representing the milliseconds between the specified date and time and midnight on January 1, 1970 (GMT time). |
---|---|
JavaScript version: | ECMAScript 1 |
Webbläsarsupport
Metoder | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
parse() | Stöd | Stöd | Stöd | Stöd | Stöd |
- Föregående sida nu()
- Nästa sida prototype
- Gå tillbaka till föregående nivå JavaScript Date Referens manual