--- title: Date.now() slug: Web/JavaScript/Reference/Global_Objects/Date/now tags: - Date - JavaScript - Method - Reference - Time - polyfill translation_of: Web/JavaScript/Reference/Global_Objects/Date/now ---
Date.now() 메소드는 UTC 기준으로 1970년 1월 1일 0시 0분 0초부터 현재까지 경과된 밀리 초를 반환합니다.
{{EmbedInteractiveExample("pages/js/date-now.html")}}
var timeInMs = Date.now();
1970년 1월 1일 0시 0분 0초부터 현재까지 경과된 밀리 초를 나타내는 숫자입니다.
now() 메소드는 1970년 1월 1일 0시 0분 0초부터 현재까지 경과된 밀리 초를 {{jsxref("Number")}} 형으로 반환합니다.
now()는 {{jsxref("Date")}}의 정적 메소드이기 때문에, 항상 Date.now() 처럼 사용하셔야 합니다.
이 메소드는 ECMA-262 5판에서 표준화되었습니다. 아직 이 메소드를 지원하도록 갱신되지 않은 엔진들은 이 메소드의 미지원에 대한 차선책으로 다음 코드를 활용하실 수 있습니다.
if (!Date.now) {
Date.now = function now() {
return new Date().getTime();
};
}
타이밍 공격 및 핑거 프린팅에 대한 보호를 제공하기 위해 Date.now ()의 정밀도는 브라우저 설정에 따라 반올림 될 수 있습니다.
Firefox에서는 privacy.reduceTimerPrecision 기본 설정이 기본적으로 활성화되어 있으며 Firefox 59에서는 기본값이 20µs입니다. 60 분에는 2ms가됩니다.
// Firefox 60에서 시간 정밀도 (2ms) 감소 Date.now(); // 1519211809934 // 1519211810362 // 1519211811670 // ... // `privacy.resistFingerprinting`을 활성화하여 시간 정밀도 감소 Date.now(); // 1519129853500 // 1519129858900 // 1519129864400 // ...
Firefox에서는 privacy.resistFingerprinting을 활성화 할 수도 있습니다. 정밀도는 100ms 또는 privacy.resistFingerprinting.reduceTimerPrecision.microseconds 중 더 큰 값이됩니다.
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('ES5.1', '#sec-15.9.4.4', 'Date.now')}} | {{Spec2('ES5.1')}} | Initial definition. Implemented in JavaScript 1.5. |
| {{SpecName('ES6', '#sec-date.now', 'Date.now')}} | {{Spec2('ES6')}} | |
| {{SpecName('ESDraft', '#sec-date.now', 'Date.now')}} | {{Spec2('ESDraft')}} |
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | {{CompatChrome("5")}} | {{CompatGeckoDesktop("1.9")}} | {{CompatIE("9")}} | {{CompatOpera("10.50")}} | {{CompatSafari("4")}} |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |