parse()
parses a date string and returns the time difference since January 1, 1970.
parse()
returns the time difference in milliseconds.
Calculate the number of years between January 1, 1970 to March 21, 2012:
// Calculate milliseconds in a year
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;
// Compute years
const d = Date.parse("March 21, 2012");
let years = Math.round(d / year);
Try it Yourself »
parse()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
Date.parse(
datestring)
datestring | Required. A string representing a date. |
A number. Milliseconds since January 1, 1970 00:00:00 UTC. |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!