静态
Date.now()
method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
var timeInMs = Date.now();
A
Number
representing the milliseconds elapsed since the UNIX epoch.
This method was standardized in ECMA-262 5 th edition. Engines which have not been updated to support this method can work around the absence of this method using the following shim:
if (!Date.now) {
Date.now = function now() {
return new Date().getTime();
};
}
To offer protection against timing attacks and fingerprinting, the precision of
Date.now()
might get rounded depending on browser settings.
In Firefox, the
privacy.reduceTimerPrecision
preference is enabled by default and defaults to 20µs in Firefox 59; in 60 it will be 2ms.
// reduced time precision (2ms) in Firefox 60 Date.now() // 1519211809934 // 1519211810362 // 1519211811670 // ... // reduced time precision with `privacy.resistFingerprinting` enabled Date.now(); // 1519129853500 // 1519129858900 // 1519129864400 // ...
In Firefox, you can also enable
privacy.resistFingerprinting
, the precision will be 100ms or the value of
privacy.resistFingerprinting.reduceTimerPrecision.microseconds
, whichever is larger.
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Date.now' in that specification. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
now
|
Chrome 5 | Edge 12 | Firefox 3 | IE 9 | Opera 10.5 | Safari 4 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 14 | Safari iOS 4 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持
Performance.now()
— provides timestamps with sub-millisecond resolution for use in measuring web page performance
console.time
/
console.timeEnd
Date
Date.UTC()
Date.now()
Date.parse()
Date.prototype.getDate()
Date.prototype.getDay()
Date.prototype.getFullYear()
Date.prototype.getHours()
Date.prototype.getMilliseconds()
Date.prototype.getMinutes()
Date.prototype.getMonth()
Date.prototype.getSeconds()
Date.prototype.getTime()
Date.prototype.getTimezoneOffset()
Date.prototype.getUTCDate()
Date.prototype.getUTCDay()
Date.prototype.getUTCFullYear()
Date.prototype.getUTCHours()
Date.prototype.getUTCMilliseconds()
Date.prototype.getUTCMinutes()
Date.prototype.getUTCMonth()
Date.prototype.getUTCSeconds()
Date.prototype.getYear()
Date.prototype.setDate()
Date.prototype.setFullYear()
Date.prototype.setHours()
Date.prototype.setMilliseconds()
Date.prototype.setMinutes()
Date.prototype.setMonth()
Date.prototype.setSeconds()
Date.prototype.setTime()
Date.prototype.setUTCDate()
Date.prototype.setUTCFullYear()
Date.prototype.setUTCHours()
Date.prototype.setUTCMilliseconds()
Date.prototype.setUTCMinutes()
Date.prototype.setUTCMonth()
Date.prototype.setUTCSeconds()
Date.prototype.setYear()
Date.prototype.toDateString()
Date.prototype.toGMTString()
Date.prototype.toISOString()
Date.prototype.toJSON()
Date.prototype.toLocaleDateString()
Date.prototype.toLocaleString()
Date.prototype.toLocaleTimeString()
Date.prototype.toSource()
Date.prototype.toString()
Date.prototype.toTimeString()
Date.prototype.toUTCString()
Date.prototype.valueOf()
Date.prototype[@@toPrimitive]
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()