--- title: Date.prototype.toISOString() slug: Web/JavaScript/Reference/Global_Objects/Date/toISOString tags: - Date - JavaScript - Method - Prototype - Reference - polyfill translation_of: Web/JavaScript/Reference/Global_Objects/Date/toISOString ---
toISOString()
메서드는 단순화한 확장 ISO 형식(ISO 8601)의 문자열을 반환합니다. 반환값은 언제나 24글자 또는 27글자(각각 YYYY-MM-DDTHH:mm:ss.sssZ
또는 ±YYYYYY-MM-DDTHH:mm:ss.sssZ
)입니다. 시간대는 언제나 UTC이며 접미어 "Z
"로 표현합니다.
dateObj.toISOString()
주어진 날짜를 국제표준시 기준 ISO 8601 형식으로 표현한 문자열.
toISOString()
사용하기아래 예제는 비표준 문자열의 분석을 포함하고 있어 비 Mozilla 브라우저에서는 올바르게 작동하지 않을 수 있습니다.
const today = new Date('05 October 2011 14:48 UTC'); console.log(today.toISOString()); // Returns 2011-10-05T14:48:00.000Z
toISOString
은 ECMA-262 제5판에 표준으로 자리잡았습니다. 아직 지원하지 않는 환경에서는 다음 코드를 추가해 대체할 수 있습니다.
if (!Date.prototype.toISOString) { (function() { function pad(number) { if (number < 10) { return '0' + number; } return number; } Date.prototype.toISOString = function() { return this.getUTCFullYear() + '-' + pad(this.getUTCMonth() + 1) + '-' + pad(this.getUTCDate()) + 'T' + pad(this.getUTCHours()) + ':' + pad(this.getUTCMinutes()) + ':' + pad(this.getUTCSeconds()) + '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + 'Z'; }; }()); }
Specification | Status | Comment |
---|---|---|
{{SpecName('ES5.1', '#sec-15.9.5.43', 'Date.prototype.toISOString')}} | {{Spec2('ES5.1')}} | Initial definition. Implemented in JavaScript 1.8. |
{{SpecName('ES6', '#sec-date.prototype.toisostring', 'Date.prototype.toISOString')}} | {{Spec2('ES6')}} | |
{{SpecName('ESDraft', '#sec-date.prototype.toisostring', 'Date.prototype.toISOString')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Date.toISOString")}}