From 943beeb7d631794a1feced4baf962fdd3a35fe08 Mon Sep 17 00:00:00 2001 From: alattalatta Date: Tue, 8 Jun 2021 22:47:21 +0900 Subject: [ko] Add Date() constructor (#992) --- files/ko/_redirects.txt | 2 +- .../reference/global_objects/date/index.html | 184 --------- .../reference/global_objects/date/date/index.html | 205 ++++++++++ .../reference/global_objects/date/index.html | 433 +++++++++++++-------- 4 files changed, 466 insertions(+), 358 deletions(-) delete mode 100644 files/ko/conflicting/web/javascript/reference/global_objects/date/index.html create mode 100644 files/ko/web/javascript/reference/global_objects/date/date/index.html (limited to 'files/ko') diff --git a/files/ko/_redirects.txt b/files/ko/_redirects.txt index 98adea837f..c90cff6132 100644 --- a/files/ko/_redirects.txt +++ b/files/ko/_redirects.txt @@ -890,7 +890,7 @@ /ko/docs/Web/JavaScript/Reference/Global_Objects/Boolean/constructor /ko/docs/Web/JavaScript/Reference/Global_Objects/Boolean /ko/docs/Web/JavaScript/Reference/Global_Objects/Boolean/prototype /ko/docs/conflicting/Web/JavaScript/Reference/Global_Objects/Boolean /ko/docs/Web/JavaScript/Reference/Global_Objects/Date/constructor /ko/docs/Web/JavaScript/Reference/Global_Objects/Date -/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype /ko/docs/conflicting/Web/JavaScript/Reference/Global_Objects/Date +/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype /ko/docs/Web/JavaScript/Reference/Global_Objects/Date /ko/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat /ko/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat /ko/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/prototype /ko/docs/conflicting/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat /ko/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype /ko/docs/Web/JavaScript/Reference/Global_Objects/Function diff --git a/files/ko/conflicting/web/javascript/reference/global_objects/date/index.html b/files/ko/conflicting/web/javascript/reference/global_objects/date/index.html deleted file mode 100644 index 4b84cc87cf..0000000000 --- a/files/ko/conflicting/web/javascript/reference/global_objects/date/index.html +++ /dev/null @@ -1,184 +0,0 @@ ---- -title: Date.prototype -slug: conflicting/Web/JavaScript/Reference/Global_Objects/Date -tags: - - Date - - JavaScript - - Property - - Prototype - - Reference -translation_of: Web/JavaScript/Reference/Global_Objects/Date -translation_of_original: Web/JavaScript/Reference/Global_Objects/Date/prototype -original_slug: Web/JavaScript/Reference/Global_Objects/Date/prototype ---- -
{{JSRef}}
- -

Date.prototype 속성은 {{jsxref("Date")}} 생성자의 프로토타입을 나타냅니다.

- -
{{js_property_attributes(0, 0, 1)}}
- -

설명

- -

JavaScript {{jsxref("Date")}} 인스턴스는 Date.prototype을 상속합니다. 생성자의 프로토타입을 변경해 모든 Date 인스턴스의 속성과 메서드를 수정할 수 있습니다.

- -

2000년대 달력과의 호환성을 위해 연도는 언제나 완전하게 네 자리 숫자로 작성해야 합니다. 즉 98 대신 1998이 올바른 작성법입니다. Date는 완전한 연도 설정에 도움이 될 {{jsxref("Date.prototype.getFullYear()", "getFullYear()")}}, {{jsxref("Date.prototype.setFullYear()", "setFullYear()")}}, {{jsxref("Date.prototype.getUTCFullYear()", "getUTCFullYear()")}}, {{jsxref("Date.prototype.setUTCFullYear()", "setUTCFullYear()")}} 메서드를 가지고 있습니다.

- -

ECMAScript 6부터 Date.prototype은 {{jsxref("Date")}} 인스턴스가 아닌 평범한 객체입니다.

- -

속성

- -
-
Date.prototype.constructor
-
인스턴스 생성에 사용한 생성자를 반환합니다. 기본값은 {{jsxref("Date")}}입니다.
-
- -

메서드

- -

접근자

- -
-
{{jsxref("Date.prototype.getDate()")}}
-
주어진 날짜의 일(1-31)을 현지 시간에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getDay()")}}
-
주어진 날짜의 요일(0-6)을 현지 시간에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getFullYear()")}}
-
주어진 날짜의 연도(4자리 수)를 현지 시간에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getHours()")}}
-
주어진 날짜의 시(0-23)를 현지 시간에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getMilliseconds()")}}
-
주어진 날짜의 밀리초(0-999)를 현지 시간에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getMinutes()")}}
-
주어진 날짜의 분(0-59)을 현지 시간에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getMonth()")}}
-
주어진 날짜의 월(0-11)을 현지 시간에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getSeconds()")}}
-
주어진 날짜의 초(0-59)를 현지 시간에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getTime()")}}
-
주어진 날짜와 1970년 1월 1일 0시 0분(UTC)의 차이를 밀리초로 반환합니다.
-
{{jsxref("Date.prototype.getTimezoneOffset()")}}
-
현재 로케일의 시간대 차이를 분으로 환산해 반환합니다.
-
{{jsxref("Date.prototype.getUTCDate()")}}
-
주어진 날짜의 일(1-31)을 UTC에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getUTCDay()")}}
-
주어진 날짜의 요일(0-6)을 UTC에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getUTCFullYear()")}}
-
주어진 날짜의 연도(4자리 수)를 UTC에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getUTCHours()")}}
-
주어진 날짜의 시(0-23)를 UTC에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getUTCMilliseconds()")}}
-
주어진 날짜의 밀리초(0-999)를 UTC에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getUTCMinutes()")}}
-
주어진 날짜의 분(0-59)을 UTC에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getUTCMonth()")}}
-
주어진 날짜의 월(0-11)을 UTC에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getUTCSeconds()")}}
-
주어진 날짜의 초(0-59)를 UTC에 맞춰 반환합니다.
-
{{jsxref("Date.prototype.getYear()")}} {{deprecated_inline}}
-
주어진 날짜의 연도(주로 두세자리 숫자)를 현지 시간에 맞춰 반환합니다. {{jsxref("Date.prototype.getFullYear()", "getFullYear()")}}를 사용하세요.
-
- -

설정자

- -
-
{{jsxref("Date.prototype.setDate()")}}
-
Sets the day of the month for a specified date according to local time.
-
{{jsxref("Date.prototype.setFullYear()")}}
-
Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to local time.
-
{{jsxref("Date.prototype.setHours()")}}
-
Sets the hours for a specified date according to local time.
-
{{jsxref("Date.prototype.setMilliseconds()")}}
-
Sets the milliseconds for a specified date according to local time.
-
{{jsxref("Date.prototype.setMinutes()")}}
-
Sets the minutes for a specified date according to local time.
-
{{jsxref("Date.prototype.setMonth()")}}
-
Sets the month for a specified date according to local time.
-
{{jsxref("Date.prototype.setSeconds()")}}
-
Sets the seconds for a specified date according to local time.
-
{{jsxref("Date.prototype.setTime()")}}
-
Sets the {{jsxref("Date")}} object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC, allowing for negative numbers for times prior.
-
{{jsxref("Date.prototype.setUTCDate()")}}
-
Sets the day of the month for a specified date according to universal time.
-
{{jsxref("Date.prototype.setUTCFullYear()")}}
-
Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to universal time.
-
{{jsxref("Date.prototype.setUTCHours()")}}
-
Sets the hour for a specified date according to universal time.
-
{{jsxref("Date.prototype.setUTCMilliseconds()")}}
-
Sets the milliseconds for a specified date according to universal time.
-
{{jsxref("Date.prototype.setUTCMinutes()")}}
-
Sets the minutes for a specified date according to universal time.
-
{{jsxref("Date.prototype.setUTCMonth()")}}
-
Sets the month for a specified date according to universal time.
-
{{jsxref("Date.prototype.setUTCSeconds()")}}
-
Sets the seconds for a specified date according to universal time.
-
{{jsxref("Date.prototype.setYear()")}} {{deprecated_inline}}
-
Sets the year (usually 2-3 digits) for a specified date according to local time. Use {{jsxref("Date.prototype.setFullYear()", "setFullYear()")}} instead.
-
- -

변환 접근자

- -
-
{{jsxref("Date.prototype.toDateString()")}}
-
Returns the "date" portion of the {{jsxref("Date")}} as a human-readable string like 'Thu Apr 12 2018'
-
{{jsxref("Date.prototype.toISOString()")}}
-
Converts a date to a string following the ISO 8601 Extended Format.
-
{{jsxref("Date.prototype.toJSON()")}}
-
Returns a string representing the {{jsxref("Date")}} using {{jsxref("Date.prototype.toISOString()", "toISOString()")}}. Intended for use by {{jsxref("JSON.stringify()")}}.
-
{{jsxref("Date.prototype.toGMTString()")}} {{deprecated_inline}}
-
Returns a string representing the {{jsxref("Date")}} based on the GMT (UT) time zone. Use {{jsxref("Date.prototype.toUTCString()", "toUTCString()")}} instead.
-
{{jsxref("Date.prototype.toLocaleDateString()")}}
-
Returns a string with a locality sensitive representation of the date portion of this date based on system settings.
-
{{jsxref("Date.prototype.toLocaleFormat()")}} {{non-standard_inline}}
-
Converts a date to a string, using a format string.
-
{{jsxref("Date.prototype.toLocaleString()")}}
-
Returns a string with a locality sensitive representation of this date. Overrides the {{jsxref("Object.prototype.toLocaleString()")}} method.
-
{{jsxref("Date.prototype.toLocaleTimeString()")}}
-
Returns a string with a locality sensitive representation of the time portion of this date based on system settings.
-
{{jsxref("Date.prototype.toSource()")}} {{non-standard_inline}}
-
Returns a string representing the source for an equivalent {{jsxref("Date")}} object; you can use this value to create a new object. Overrides the {{jsxref("Object.prototype.toSource()")}} method.
-
{{jsxref("Date.prototype.toString()")}}
-
Returns a string representing the specified {{jsxref("Date")}} object. Overrides the {{jsxref("Object.prototype.toString()")}} method.
-
{{jsxref("Date.prototype.toTimeString()")}}
-
Returns the "time" portion of the {{jsxref("Date")}} as a human-readable string.
-
{{jsxref("Date.prototype.toUTCString()")}}
-
Converts a date to a string using the UTC timezone.
-
{{jsxref("Date.prototype.valueOf()")}}
-
Returns the primitive value of a {{jsxref("Date")}} object. Overrides the {{jsxref("Object.prototype.valueOf()")}} method.
-
- -

명세

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.9.5', 'Date.prototype')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-properties-of-the-date-prototype-object', 'Date.prototype')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-properties-of-the-date-prototype-object', 'Date.prototype')}}{{Spec2('ESDraft')}} 
- -

브라우저 호환성

- - - -

{{Compat("javascript.builtins.Date.prototype")}}

diff --git a/files/ko/web/javascript/reference/global_objects/date/date/index.html b/files/ko/web/javascript/reference/global_objects/date/date/index.html new file mode 100644 index 0000000000..08e2410310 --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/date/date/index.html @@ -0,0 +1,205 @@ +--- +title: Date() 생성자 +slug: Web/JavaScript/Reference/Global_Objects/Date/Date +tags: + - Constructor + - Date + - JavaScript + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Date/Date +browser-compat: javascript.builtins.Date.Date +--- + +
{{JSRef}}
+ +

+ Date 생성자는 시간의 특정 지점을 나타내는 Date 객체를 플랫폼에 종속되지 않는 형태로 생성합니다. + Date 객체는 1970년 1월 1일 UTC(국제표준시) 자정으로부터 지난 시간을 밀리초로 나타내는 UNIX 타임스탬프를 + 담습니다. +

+ +
{{EmbedInteractiveExample("pages/js/date-constructor.html")}}
+ +

구문

+ +
+new Date()
+new Date(value)
+new Date(dateString)
+
+new Date(year, monthIndex)
+new Date(year, monthIndex, day)
+new Date(year, monthIndex, day, hours)
+new Date(year, monthIndex, day, hours, minutes)
+new Date(year, monthIndex, day, hours, minutes, seconds)
+new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds)
+
+ +
+

+ 참고: 새로운 Date 객체를 생성하는 방법은 {{jsxref("operators/new", "new")}} 연산자를 + 사용하는 것이 유일합니다. now = Date()처럼 Date를 직접 호출하면 새로운 + Date 객체가 아니라 문자열을 반환합니다. +

+
+ +

매개변수

+ +

Date() 생성자는 네 가지 형태로 사용할 수 있습니다.

+ +
    +
  1. +

    매개변수 없음

    + +

    + 매개변수를 제공하지 않으면, 생성 순간의 날짜와 시간을 나타내는 + Date 객체를 생성합니다. +

    +
  2. +
  3. +

    UNIX 타임스탬프 값

    + +
    +
    + value +
    +
    + UNIX 타임스탬프, + 즉 1970년 1월 1일 00:00:00 UTC(UNIX 시간)부터의 시간을 밀리초 단위로 표현하되 윤초는 무시한 정수 값입니다. + 대부분의 UNIX 타임스탬프 함수는 초 단위까지만 정확함을 유의하세요. +
    +
    +
  4. +
  5. +

    타임스탬프 문자열

    + +
    +
    + dateString +
    +
    + {{jsxref("Date.parse()")}} 메서드가 인식할 수 있는 형태로 나타낸 날짜 문자열입니다. + IETF 호환 RFC 2822 타임스탬프와, + ISO8601의 특정 버전을 인식할 수 + 있습니다. +
    +

    + 참고: Date 생성자(및 동일한 동작의 Date.parse())를 사용한 날짜 + 파싱은 동작이 일관적이지 못하고 브라우저끼리 차이가 존재하므로 사용하지 않는 것이 좋습니다. +

    + +
      +
    • + RFC 2822 + 형식 문자열은 관례적으로만 지원하는 것 뿐입니다. +
    • +
    • + ISO 8601 형식 문자열은 시간 정보 없는 문자열("1970-01-01" + 등)을 현지 시간이 아닌 UTC 기준으로 처리하는 점에서 표준과 다릅니다. +
    • +
    +
    +
    +
    +
  6. +
  7. +

    개별 날짜 및 시간 구성 요소

    + +

    + 최소한 연도와 월이 주어졌을 때, Date()의 이 형태는 Date 객체를 생성할 때 모든 구성 + 요소(연, 월, 일, 시, 분, 초, 밀리초)를 모두 매개변수에서 가져옵니다. 누락한 요소에는 가장 낮은 + 값(day는 1, 나머지는 0)을 사용합니다. 모든 매개변수 값은 UTC가 아닌 현지 시간으로 취급합니다. +

    + +
    +
    + year +
    +
    +

    연도를 나타내는 정수 값입니다.

    + +

    + 0부터 99까지는 1900부터 1999로 처리합니다. 다른 모든 값은 + 그대로 사용합니다. + 예제를 참고하세요. +

    +
    +
    + monthIndex +
    +
    + 월을 나타내는 정수 값입니다. 1월을 나타내는 0부터 12월을 나타내는 11까지 사용할 수 + 있습니다. +
    +
    + day {{optional_inline}} +
    +
    일을 나타내는 정수 값입니다. 기본값은 1입니다.
    +
    + hours {{optional_inline}} +
    +
    + 시를 나타내는 정수 값입니다. 기본 값은 자정을 나타내는 + 0입니다. +
    +
    + minutes {{optional_inline}} +
    +
    + 분을 나타내는 정수 값입니다. 기본 값은 정각을 나타내는 + 0입니다. +
    +
    + seconds {{optional_inline}} +
    +
    + 초를 나타내는 정수 값입니다. 기본 값은 + 0초입니다. +
    +
    + milliseconds {{optional_inline}} +
    +
    + 밀리초를 나타내는 정수 값입니다. 기본 값은 + 0밀리초입니다. +
    +
    +
  8. +
+ +

예제

+ +

Date 객체를 만드는 여러가지 방법

+ +

아래 예제는 JavaScript 날짜를 생성하는 몇 가지 방법을 보입니다.

+ +
+

+ 참고: Date 생성자(및 동일한 동작의 Date.parse())를 사용한 날짜 파싱은 + 동작이 일관적이지 못하고 브라우저끼리 차이가 존재하므로 사용하지 않는 것이 좋습니다. +

+
+ +
+let today = new Date()
+let birthday = new Date('December 17, 1995 03:24:00')
+let birthday = new Date('1995-12-17T03:24:00')
+let birthday = new Date(1995, 11, 17)            // 월은 0부터 시작
+let birthday = new Date(1995, 11, 17, 3, 24, 0)
+ +

명세

+ +{{Specifications}} + +

브라우저 호환성

+ +

{{Compat}}

+ +

같이 보기

+ + diff --git a/files/ko/web/javascript/reference/global_objects/date/index.html b/files/ko/web/javascript/reference/global_objects/date/index.html index d9cf05bbdb..54c5f9fa44 100644 --- a/files/ko/web/javascript/reference/global_objects/date/index.html +++ b/files/ko/web/javascript/reference/global_objects/date/index.html @@ -2,238 +2,325 @@ title: Date slug: Web/JavaScript/Reference/Global_Objects/Date tags: - - Constructor + - Class - Date - JavaScript - Reference - 날짜 - 시간 translation_of: Web/JavaScript/Reference/Global_Objects/Date +browser-compat: javascript.builtins.Date --- -
{{JSRef}}
- -

Date 생성자는 시간의 특정 지점을 나타내는 Date 객체를 생성합니다. Date 객체는 1970년 1월 1일 UTC(국제표준시) 00:00으로부터 지난 시간을 밀리초로 나타내는 유닉스 타임스탬프를 사용합니다.

- -
{{EmbedInteractiveExample("pages/js/date-constructor.html")}}
- - -

Date 객체 초기화

+
{{JSRef}}
-

JavaScript Date 객체를 생성하는 법은 {{jsxref("new")}} 연산자를 사용하는 것이 유일합니다.

+

+ JavaScript Date 객체는 시간의 한 점을 플랫폼에 종속되지 않는 형태로 나타냅니다. + Date 객체는 1970년 1월 1일 UTC(협정 세계시) 자정과의 시간 차이를 밀리초로 나타내는 정수 값을 담습니다. +

+ +
+

+ 참고: TC39에서 새로운 날짜/시간 API인 + Temporal을 작업 중입니다. + Igalia 블로그에서 더 + 알아보세요. 아직 프로덕션에는 적합하지 않습니다! +

+
-
let now = new Date();
+

설명

-

단순히 {{jsxref("Date", "Date")}} 객체를 직접 호출했을 때, 반환 값은 Date 객체가 아니라 날짜를 나타낸 문자열입니다. JavaScript는 Date 리터럴 구문이 없습니다.

+

ECMAScript 시간과 타임스탬프

-

구문

+

+ JavaScript 날짜의 기반은 1970년 1월 1일 UTC 자정과의 시간 차이를 밀리초 단위로 나타낸 것으로, 날짜와 시간의 컴퓨터 + 기록물을 대부분 차지하고 있는 UNIX 시간(UNIX epoch, 1970년 1월 1일 자정과의 시간 차이를 초 단위로 + 나타냄)과는 다릅니다. +

-
new Date();
-new Date(value);
-new Date(dateString);
-new Date(year, monthIndex[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);
-
+
+

+ 참고: Date 객체의 중심을 구성하는 시간 값은 UTC 기준이지만, 날짜와 시간 등 구성 요소를 + 가져오는 메서드는 모두 현지(호스트 시스템의 위치)의 시간대를 사용한다는 것을 기억해야 합니다. +

+
-

매개변수

+

+ Date의 최대 값은 JavaScript에서의 안전한 최대 정수와 같지 않습니다. + ({{jsxref("Number.MAX_SAFE_INTEGER")}}는 9,007,199,254,740,991입니다.) 대신, ECMA-262는 1970년 1월 1일 UTC에서 + ±100,000,000일(1억일)을 표준 Date 객체의 최대 범위로 규정하고 있습니다. 이는 기원전 271821년 4월 20일부터 + 서력 275760년 9월 13일까지에 해당하는 범위로, ±8,640,000,000,000,000 밀리초와 같습니다. +

-

Date() 생성자는 네 가지 형태로 사용할 수 있습니다.

+

날짜 형식과 시간대 변환

-

매개변수 없음

+

+ 날짜를 얻거나 시간대끼리 변환하는 메서드가 다수 존재하며, 그 중 특히 유용한 함수는 날짜 및 시간을 국제 표준 시간인 + 협정 세계시(UTC)로 반환하는 함수입니다. (UTC는 그리니치 시간대라고도 불리는데, 기준 시간대가 영국의 런던 인근인 + 그리니치를 지나는 경선이기 때문입니다.) 사용자의 장치는 현지 시간을 제공합니다. +

-

매개변수를 제공하지 않으면, 현지 시간으로 생성 순간의 날짜와 시간을 나타내는 Date 객체를 생성합니다.

+

+ {{jsxref("Date.getDay", "getDay()")}}와 {{jsxref("Date.setHours", "setHours()")}}처럼 구성 요소를 현지 시간 기준으로 + 읽고 쓰는 메서드에는 {{jsxref("Date.getUTCDay", "getUTCDay()")}}와 {{jsxref("Date.setUTCHours", "setUTCHours()")}}처럼 + UTC를 기준으로 하는 읽기/쓰기 메서드도 존재합니다. +

-

유닉스 타임스탬프

+

생성자

-
value
-
유닉스 타임스탬프, 즉 1970년 1월 1일 00:00:00 UTC(유닉스 시간)부터의 시간을 밀리초 단위로 표현하되 윤초는 무시한 정숫값. 대부분의 유닉스 타임스탬프 함수는 초 단위까지만 정확함을 유의하세요.
-
-

타임스탬프 문자열

-
-
dateString
-
날짜를 표현하는 문자열값. {{jsxref("Date.parse()")}} 메서드가 인식할 수 있는 형식(IETF 호환 RFC 2822 타임스탬프ISO8601의 한 버전)이어야 합니다 -
참고: Date 생성자(와 Date.parse)를 사용해 날짜 문자열에서 시간을 알아내는건 하지 않는 것이 좋습니다. 브라우저 간 차이와 여러 비일관성이 존재하며 RFC 2822 규격 문자열의 지원은 관례일 뿐입니다. ISO 8601 규격 문자열은 시간 정보가 없을 때("1970-01-01" 등) 현지 시간이 아닌 UTC 기준으로 처리합니다.
-
+
{{jsxref("Date/Date", "Date()")}}
+
+ 함수로 호출할 경우 new Date().toString()과 동일하게 현재 날짜와 시간을 나타내는 문자열을 반환합니다. +
+
{{jsxref("Date/Date", "new Date()")}}
+
생성자로 호출할 경우 새로운 Date 객체를 반환합니다.
-

개별 날짜 및 시간 구성 요소

- -

적어도 연도와 월이 주어지면, 자신의 구성 요소(연, 월, 일, 시, 분, 초, 밀리초)를 모두 매개변수의 값에서 가져오는 Date 객체를 생성합니다. 누락한 요소에는 가장 낮은 값(day는 1, 나머지는 0)을 사용합니다.

+

정적 메서드

-
year
-
연도를 나타내는 정숫값. 0부터 99는 1900부터 1999로 처리합니다. {{anch("두 자리 연도는 1900년대로", "아래 예제")}}를 참고하세요.
-
monthIndex
-
월을 나타내는 정숫값. 0은 1월을 나타내고 11은 12월을 나타냅니다.
-
day {{optional_inline}}
-
일을 나타내는 정숫값. 기본값은 1입니다.
-
hours {{optional_inline}}
-
시를 나타내는 정숫값. 기본값은 0(자정)입니다.
+
{{jsxref("Date.now()")}}
+
1970년 1월 1일 00:00:00 UTC로부터 지난 시간을 밀리초 단위의 숫자 값으로 반환합니다. 윤초는 무시합니다.
+
{{jsxref("Date.parse()")}}
+
+ 날짜를 나타내는 문자열을 분석한 후, 해당 날짜와 1970년 1월 1일 00:00:00 UTC의 시간 차이를 밀리초 단위의 숫자 값으로 + 반환합니다. +
+

+ 참고: Date.parse()를 사용한 날짜 분석은 브라우저 간 차이 및 일관적이지 못한 동작을 + 가지고 있으므로 사용하지 않는 것이 좋습니다. +

+
+
+
{{jsxref("Date.UTC()")}}
+
+ 생성자가 받을 수 있는 제일 많은 매개변수(구성요소 각각, 2개 ~ 7개)를 동일하게 받아서, 1970년 1월 1일 00:00:00 UTC의 + 시간 차이를 밀리초 단위의 숫자 값으로 반환합니다. 윤초는 무시합니다. +
+

인스턴스 메서드

+
-
minutes {{optional_inline}}
-
분을 나타내는 정숫값. 기본값은 0분입니다.
-
seconds {{optional_inline}}
-
초를 나타내는 정숫값. 기본값은 0초입니다.
-
milliseconds {{optional_inline}}
-
밀리초를 나타내는 정숫값. 기본값은 0밀리초입니다.
+
{{jsxref("Date.prototype.getDate()")}}
+
Date에서 현지 시간 기준 일(131)을 반환합니다.
+
{{jsxref("Date.prototype.getDay()")}}
+
Date에서 현지 시간 기준 요일(06)을 반환합니다.
+
{{jsxref("Date.prototype.getFullYear()")}}
+
Date에서 현지 시간 기준 연도(네 자리 연도면 네 자리로)를 반환합니다.
+
{{jsxref("Date.prototype.getHours()")}}
+
Date에서 현지 시간 기준 시(023)를 반환합니다.
+
{{jsxref("Date.prototype.getMilliseconds()")}}
+
Date에서 현지 시간 기준 밀리초(0999)를 반환합니다.
+
{{jsxref("Date.prototype.getMinutes()")}}
+
Date에서 현지 시간 기준 분(059)을 반환합니다.
+
{{jsxref("Date.prototype.getMonth()")}}
+
Date에서 현지 시간 기준 월(011)을 반환합니다.
+
{{jsxref("Date.prototype.getSeconds()")}}
+
Date에서 현지 시간 기준 초(059)를 반환합니다.
+
{{jsxref("Date.prototype.getTime()")}}
+
+ 1970년 1월 1일 00:00:00 UTC로부터의 경과시간을 밀리초 단위로 반환합니다. Date가 기준 + 시간 이전을 나타낼 경우 음수 값을 반환합니다. +
+
{{jsxref("Date.prototype.getTimezoneOffset()")}}
+
현지 시간대와 UTC의 차이를 분 단위로 반환합니다.
+
{{jsxref("Date.prototype.getUTCDate()")}}
+
Date에서 국제 시간 기준 일(131)을 반환합니다.
+
{{jsxref("Date.prototype.getUTCDay()")}}
+
Date에서 국제 시간 기준 요일(06)을 반환합니다.
+
{{jsxref("Date.prototype.getUTCFullYear()")}}
+
Date에서 국제 시간 기준 연도(네 자리 연도면 네 자리로)를 반환합니다.
+
{{jsxref("Date.prototype.getUTCHours()")}}
+
Date에서 국제 시간 기준 시(023)를 반환합니다.
+
{{jsxref("Date.prototype.getUTCMilliseconds()")}}
+
Date에서 국제 시간 기준 밀리초(0999)를 반환합니다.
+
{{jsxref("Date.prototype.getUTCMinutes()")}}
+
Date에서 국제 시간 기준 분(059)을 반환합니다.
+
{{jsxref("Date.prototype.getUTCMonth()")}}
+
Date에서 국제 시간 기준 월(011)을 반환합니다.
+
{{jsxref("Date.prototype.getUTCSeconds()")}}
+
Date에서 국제 시간 기준 초(059)를 반환합니다.
+
{{jsxref("Date.prototype.setDate()")}}
+
현지 시간 기준으로 일을 설정합니다.
+
{{jsxref("Date.prototype.setFullYear()")}}
+
현지 시간 기준으로 연도(네 자리 연도면 네 자리로)를 설정합니다.
+
{{jsxref("Date.prototype.setHours()")}}
+
현지 시간 기준으로 시를 설정합니다.
+
{{jsxref("Date.prototype.setMilliseconds()")}}
+
현지 시간 기준으로 밀리초를 설정합니다.
+
{{jsxref("Date.prototype.setMinutes()")}}
+
현지 시간 기준으로 분을 설정합니다.
+
{{jsxref("Date.prototype.setMonth()")}}
+
현지 시간 기준으로 월을 설정합니다.
+
{{jsxref("Date.prototype.setSeconds()")}}
+
현지 시간 기준으로 초를 설정합니다.
+
{{jsxref("Date.prototype.setTime()")}}
+
+ Date가 나타낼 시간을 1970년 1월 1일 00:00:00 UTC로부터의 경과시간(밀리초)으로 설정합니다. 기준 이전의 시간은 음수 값을 사용해 설정할 수 있습니다. +
+
{{jsxref("Date.prototype.setUTCDate()")}}
+
국제 시간 기준으로 일을 설정합니다.
+
{{jsxref("Date.prototype.setUTCFullYear()")}}
+
국제 시간 기준으로 연도(네 자리 연도면 네 자리로)를 설정합니다.
+
{{jsxref("Date.prototype.setUTCHours()")}}
+
국제 시간 기준으로 시를 설정합니다.
+
{{jsxref("Date.prototype.setUTCMilliseconds()")}}
+
국제 시간 기준으로 밀리초를 설정합니다.
+
{{jsxref("Date.prototype.setUTCMinutes()")}}
+
국제 시간 기준으로 분을 설정합니다.
+
{{jsxref("Date.prototype.setUTCMonth()")}}
+
국제 시간 기준으로 월을 설정합니다.
+
{{jsxref("Date.prototype.setUTCSeconds()")}}
+
국제 시간 기준으로 초를 설정합니다.
+
{{jsxref("Date.prototype.toDateString()")}}
+
Date의 날짜 부분만 나타내는, 사람이 읽을 수 있는 문자열을 반환합니다.
+
{{jsxref("Date.prototype.toISOString()")}}
+
Date를 나타내는 문자열을 ISO 8601 확장 형식에 맞춰 반환합니다.
+
{{jsxref("Date.prototype.toJSON()")}}
+
+ {{jsxref("Date.prototype.toISOString()", "toISOString()")}}을 사용해서 {{jsxref("Date")}}를 나타내는 문자열을 + 반환합니다. {{jsxref("JSON.stringify()")}}에서 사용합니다. +
+
{{jsxref("Date.prototype.toLocaleDateString()")}}
+
Date의 날짜 부분을 나타내는 문자열을 시스템에 설정된 현재 지역의 형식으로 반환합니다.
+
{{jsxref("Date.prototype.toLocaleFormat()")}}
+
형식 문자열을 사용해서 Date를 나타내는 문자열을 생성합니다.
+
{{jsxref("Date.prototype.toLocaleString()")}}
+
+ Date를 나타내는 문자열을 현재 지역의 형식으로 반환합니다. + {{jsxref("Object.prototype.toLocaleString()")}} 메서드를 재정의합니다. +
+
{{jsxref("Date.prototype.toLocaleTimeString()")}}
+
Date의 시간 부분을 나타내는 문자열을 시스템에 설정된 현재 지역의 형식으로 반환합니다.
+
{{jsxref("Date.prototype.toString()")}}
+
+ Date를 나타내는 시간 문자열을 반환합니다. {{jsxref("Object.prototype.toString()")}} 메서드를 + 재정의합니다. +
+
{{jsxref("Date.prototype.toTimeString()")}}
+
Date의 시간 부분만 나타내는, 사람이 읽을 수 있는 문자열을 반환합니다.
+
{{jsxref("Date.prototype.toUTCString()")}}
+
Date를 나타내는 문자열을 UTC 기준으로 반환합니다.
+
{{jsxref("Date.prototype.valueOf()")}}
+
+ {{jsxref("Date")}} 객체의 원시 값을 반환합니다. {{jsxref("Object.prototype.valueOf()")}} 메서드를 재정의합니다. +
-

설명

+

예제

-

유닉스 시간과 타임스탬프

+

Date 객체를 만드는 여러가지 방법

-

JavaScript 날짜는 1970년 1월 1일 자정 (UTC)로부터 지난 시간을 밀리초 단위로 나타낸 것입니다. 이 날짜와 시간을 합쳐 유닉스 시간이라고 부릅니다. 유닉스 시간은 컴퓨터로 날짜와 시간을 기록할 때 널리 사용하는 기준점입니다.

+

아래 예제는 JavaScript 날짜를 생성하는 몇 가지 방법을 보입니다.

-
-

참고: 시간과 날짜는 현시 시간으로 저장된다는 점을 기억하는게 중요합니다. 시간, 날짜, 아니면 각각의 구성 요소를 회수하는 기본 메서드도 현지 시간에서 동작합니다.

+
+

+ 참고: Date 생성자(및 동일한 동작의 Date.parse())를 사용한 날짜 분석은 + 동작이 일관적이지 못하고 브라우저끼리 차이가 존재하므로 사용하지 않는 것이 좋습니다. +

-

하루는 86,400,000 밀리초입니다. 타임스탬프 기록에 사용하는 수의 크기를 고려했을 때, Date 객체는 유닉스 시간으로부터 약 ±100,000,000일 (1억일)을 기록할 수 있습니다. 따라서 293,742년이 오면 문제가 발생할 여지가 있습니다.

+
+let today = new Date()
+let birthday = new Date('December 17, 1995 03:24:00')
+let birthday = new Date('1995-12-17T03:24:00')
+let birthday = new Date(1995, 11, 17)            // 월은 0부터 시작
+let birthday = new Date(1995, 11, 17, 3, 24, 0)
-

날짜 형식과 시간대 변환

+

두 자리 연도는 1900년대로

-

날짜를 얻는 방법과 시간대를 바꾸는 메서드는 여럿 있습니다. 그 중 특히 유용한 함수는 날짜 및 시간을 국제 표준 시간인 협정 표준시(UTC)로 반환하는 함수입니다. UTC는 그리니치 시간대라고도 불리는데, 기준 시간대가 영국의 런던과 인근의 그리니치를 지나는 경선이기 때문입니다. 사용자의 장치는 현지 시간을 제공합니다.

+

+ Date의 연도에 0부터 99까지의 정수를 제공하면 1900부터 + 1999로 처리합니다. 다른 모든 값은 그대로 사용합니다. +

-

{{jsxref("Date.getDay", "getDay()")}}와 {{jsxref("Date.setHours", "setHours()")}}처럼 현지 시간을 기준으로 한 구성요소 읽기 및 쓰기 메서드처럼, {{jsxref("Date.getDayUTC", "getUTCDay()")}} 와 {{jsxref("Date.setHoursUTC", "setUTCHours()")}}처럼 UTC를 기준으로 하는 읽기 및 쓰기 메서드도 존재합니다.

+

+ 1900년대가 아닌, 실제 0 ~ 99년을 지정해야 하면 {{jsxref("Date.prototype.setFullYear()")}}와 + {{jsxref("Date.prototype.getFullYear()")}} 메서드를 사용해야 합니다. +

-

속성

+
+let date = new Date(98, 1)  // Sun Feb 01 1998 00:00:00 GMT+0900 (대한민국 표준시)
 
-
-
{{jsxref("Date.prototype")}}
-
Date 객체에 추가 속성을 부여할 수 있습니다.
-
Date.length
-
Date.length의 값은 7로, 생성자가 받을 수 있는 매개변수의 수입니다. 보통 유용하게 쓸 수 있는 값은 아닙니다.
-
- -

메서드

+// 구형 메서드: 여기서도 98을 1998로 처리 +date.setYear(98) // Sun Feb 01 1998 00:00:00 GMT+0900 (대한민국 표준시) -
-
{{jsxref("Date.now()")}}
-
1970년 1월 1일 00:00:00 UTC(유닉스 시간)부터 지난 시간을 밀리초 단위의 숫자 값으로 반환합니다. 윤초는 무시합니다.
-
{{jsxref("Date.parse()")}}
-
Parses a string representation of a date and returns the number of milliseconds since 1 January, 1970, 00:00:00, UTC. -
Note: Parsing of strings with Date.parse is strongly discouraged due to browser differences and inconsistencies.
-
-
{{jsxref("Date.UTC()")}}
-
Accepts the same parameters as the longest form of the constructor (i.e. 2 to 7) and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC, with leap seconds ignored.
-
- -

JavaScript Date 인스턴스

- -

All Date instances inherit from {{jsxref("Date.prototype")}}. The prototype object of the Date constructor can be modified to affect all Date instances.

- -

Date.prototype 메서드

+date.setFullYear(98) // Sat Feb 01 0098 00:00:00 GMT+0827 (대한민국 표준시) +
-
{{page('/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype', 'Methods')}}
+

경과시간 계산

-

예제

+

다음은 두 개의 JavaScript 날짜의 간격을 밀리초로 나타내는 예제입니다.

-

날짜를 지정하는 여러가지 방법

+

+ 연, 월, 일(서머타임)의 길이가 계속해서 달라지므로, 두 시간의 간격을 시/분/초보다 큰 단위로 나타낼 땐 여러가지 문제가 + 생기므로 이 방법을 시도하기 전에 관련 문제를 먼저 자세히 알아보세요. +

-

아래 예제는 날짜를 지정하는 몇가지 방법을 보여줍니다:

+
+// Date 객체 사용법
+let start = Date.now()
 
-
-

Note: parsing of date strings with the Date constructor (and Date.parse, they are equivalent) is strongly discouraged due to browser differences and inconsistencies.

-
- -
var today = new Date();
-var birthday = new Date("December 17, 1995 03:24:00");
-var birthday = new Date(95,11,17);
-var birthday = new Date(95,11,17,3,24,0);
+// 시간이 오래 걸리는 어떤 작업
+doSomethingForALongTime()
+let end = Date.now()
+let elapsed = end - start // 밀리초로 나타낸 경과시간
 
-

두 자리 연도는 1900년대로

+
+// 내장 메서드 사용법
+let start = new Date()
 
-

In order to create and get dates between the years 0 and 99 the {{jsxref("Date.prototype.setFullYear()")}} and {{jsxref("Date.prototype.getFullYear()")}} methods should be used.

+// 시간이 오래 걸리는 어떤 작업 +doSomethingForALongTime() +let end = new Date() +let elapsed = end.getTime() - start.getTime() // 밀리초로 나타낸 경과시간 +
-
var date = new Date(98, 1); // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT)
+
+// 임의의 함수를 테스트하고, 호출에 걸린 시간을 출력하려면
+function printElapsedTime(fTest) {
+  let nStartTime = Date.now(),
+      vReturn = fTest(),
+      nEndTime = Date.now()
 
-// Deprecated method, 98 maps to 1998 here as well
-date.setYear(98);           // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT)
+  console.log(`Elapsed time: ${ String(nEndTime - nStartTime) } milliseconds`)
+  return vReturn
+}
 
-date.setFullYear(98);       // Sat Feb 01 0098 00:00:00 GMT+0000 (BST)
+let yourFunctionReturn = printElapsedTime(yourFunction)
 
-

경과시간 계산

+
+

+ 참고: {{domxref("Window.performance", "Web Performance API", "", 1)}}의 고해상도 시간 기능을 + 지원하는 브라우저에서는 {{domxref("Performance.now()")}}를 사용해서 {{jsxref("Date.now()")}}보다 더 안정적이고 + 정확한 경과 시간을 알아낼 수 있습니다. +

+
-

The following examples show how to determine the elapsed time between two JavaScript dates in milliseconds.

+

ECMAScript 시간으로부터 경과한 시간을 초 단위로 가져오기

-

Due to the differing lengths of days (due to daylight saving changeover), months and years, expressing elapsed time in units greater than hours, minutes and seconds requires addressing a number of issues and should be thoroughly researched before being attempted.

+
let seconds = Math.floor(Date.now() / 1000)
-
// Date 객체 사용
-var start = Date.now();
+

+ 여기서는 정수만 반환하는 것이 중요하므로, 단순히 나누기만 해서는 충분하지 않습니다. 그리고 실제로 "지나간" 초를 + 반환해야 하므로 {{jsxref("Math.round()")}}를 사용하지 않고 {{jsxref("Math.floor()")}}를 사용합니다. +

-// 시간이 오래 걸리는 작업을 여기 배치합니다 -doSomethingForALongTime(); -var end = Date.now(); -var elapsed = end - start; // 경과 시간, 밀리초. -
+

명세

-
// 내장 메서드 사용
-var start = new Date();
+{{Specifications}}
 
-// 시간이 오래 걸리는 작업을 여기 배치합니다.
-doSomethingForALongTime();
-var end = new Date();
-var elapsed = end.getTime() - start.getTime(); // 경과 시간, 밀리초.
-
+

브라우저 호환성

-
// to test a function and get back its return
-function printElapsedTime(fTest) {
-  var nStartTime = Date.now(),
-      vReturn = fTest(),
-      nEndTime = Date.now();
+

{{Compat}}

- console.log('Elapsed time: ' + String(nEndTime - nStartTime) + ' milliseconds'); - return vReturn; -} +

같이 보기

-var yourFunctionReturn = printElapsedTime(yourFunction);
- -
Note: In browsers that support the {{domxref("window.performance", "Web Performance API", "", 1)}}'s high-resolution time feature, {{domxref("Performance.now()")}} can provide more reliable and precise measurements of elapsed time than {{jsxref("Date.now()")}}.
- -

Get the number of seconds since Unix Epoch

- -
var seconds = Math.floor(Date.now() / 1000);
- -

In this case it's important to return only an integer (so a simple division won't do), and also to only return actually elapsed seconds (that's why this code uses {{jsxref("Math.floor()")}} and not {{jsxref("Math.round()")}}).

- -

명세

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ESDraft', '#sec-date-objects', 'Date')}}{{Spec2('ESDraft')}} 
{{SpecName('ES6', '#sec-date-objects', 'Date')}}{{Spec2('ES6')}} 
{{SpecName('ES5.1', '#sec-15.9', 'Date')}}{{Spec2('ES5.1')}} 
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.1.
- -

브라우저 호환성

- - - -

{{Compat("javascript.builtins.Date", 3)}}

+
    +
  • {{jsxref("Date/Date", "Date()")}} 생성자
  • +
-- cgit v1.2.3-54-g00ecf