Date.now()
Resum
El mètode Date.now()
retorna el nombre de milisegons que han passat des de l'1 de gener de 1970 00:00:00 UTC.
Sintaxi
var timeInMs = Date.now();
Paràmetres
Cap.
Descripció
El mètode now()
retorna el nombre de method returns el nombre de milisegons que han passat des de l'1 de gener de 1970 00:00:00 UTC fins al moment actual representat en un Nombre
.
Com que now()
és un mètode estàtic de Date
, sempre es crida com a Date.now()
.
Polyfill
Aquest mètode va ser estandaritzat a la cinquena edició de l'ECMA-262. Els motors que encara no hagin sigut actualitzats per a suportar aquest mètode poden utilitzar el bocí de codi següent per a paliar l'absència d'aquest mètode:
if (!Date.now) {
Date.now = function now() {
return new Date().getTime();
};
}
Especificacions
Especificació | Estat | Comentaris |
---|---|---|
ECMAScript 5.1 (ECMA-262) The definition of 'Date.now' in that specification. |
Standard | Definició inicial. Implementat a JavaScript 1.5. |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Date.now' in that specification. |
Standard |
Compatibilitat amb navegadors
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Característiques | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | 5 | 3.0 (1.9) | 9 | 10.50 | 4 |
Característiques | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | |
---|---|---|---|---|---|---|---|
|
(Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Basat en la taula de compatibilitat de Kangax.
Vegeu també
Performance.now()
(en-US) — proporciona marques de temps amb una resolució submilimètrica per a utilitzar al mesurar el rendiment de pàgines webconsole.time()
(en-US) /console.timeEnd()
(en-US)