Date

  • 리비전 슬러그: Core_JavaScript_1.5_Reference/Global_Objects/Date
  • 리비전 제목: Date
  • 리비전 아이디: 196574
  • 제작일시:
  • 만든이: 행복한고니
  • 현재 리비전인가요? 아니오
  • 댓글

리비전 내용

요약

기본 객체

Lets you work with dates and times.

생성

Date 객체는 다음과 같이 생성한다:

new Date()
new Date(milliseconds)
new Date(dateString)
new Date(yr_num, mo_num, day_num
        [, hr_num, min_num, sec_num, ms_num])


JavaScript 1.3 이전 버전은 다음과 같다:

new Date()
new Date(milliseconds)
new Date(dateString)
new Date(yr_num, mo_num, day_num[, hr_num, min_num, sec_num])

파라미터

milliseconds 
Integer value representing the number of milliseconds since 1 January 1970 00:00:00.
dateString 
String value representing a date. The string should be in a format recognized by the parse method.
yr_num, mo_num, day_num 
Integer values representing part of a date. As an integer value, the month is represented by 0 to 11 with 0=January and 11=December.
hr_num, min_num, sec_num, ms_num 
Integer values representing part of a date.

설명

If you supply no arguments, the constructor creates a Date object for today's date and time according to local time. If you supply some arguments but not others, the missing arguments are set to 0. If you supply any arguments, you must supply at least the year, month, and day. You can omit the hours, minutes, seconds, and milliseconds.

The date is measured in milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.

The Date object provides uniform behavior across platforms.

The Date object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.

For compatibility with millennium calculations (in other words, to take into account the year 2000), you should always specify the year in full; for example, use 1998, not 98. To assist you in specifying the complete year, JavaScript includes the methods getFullYear, setFullYear, getUTCFullYear, and setUTCFullYear.

아래 예제는 timeAtimeB의 시간차를 밀리초 단위로 반환합니다.

timeA = new Date();
// Statements here to take some action.
timeB = new Date();
timeDifference = timeB - timeA;

하위 호환성

JavaScript 1.2 이하 버전

Date 객체는 다음과 같이 동작합니다:

  • 1970년 이전의 날짜는 불가능합니다.
  • JavaScript depends on platform-specific date facilities and behavior; the behavior of the Date object varies from platform to platform.
  • The getDay and getUTCDay methods behave differently on differently localized platforms (e.g. a British and a German Windows). Specifically, 0 (zero) can be returned either for Sunday or Monday.

속성

  • constructor: 객체의 프로토타입을 생성하는 함수
  • prototype: Date 객체에 추가 속성을 부여할 수 있다.

정적 메소드

  • now: Returns the numeric value corresponding to the current time.
  • parse: Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00, local time.
  • UTC: Accepts the same parameters as the longest form of the constructor, and returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.

메소드

  • getDate: 한달의 몇번째 날인지 반환
  • getDay: 주중의 몇번째 요일인지 반환
  • getFullYear: Returns the year of the specified date according to local time.
  • getHours: Returns the hour in the specified date according to local time.
  • getMilliseconds: Returns the milliseconds in the specified date according to local time.
  • getMinutes: Returns the minutes in the specified date according to local time.
  • getMonth: Returns the month in the specified date according to local time.
  • getSeconds: Returns the seconds in the specified date according to local time.
  • getTime: Returns the numeric value corresponding to the time for the specified date according to universal time.
  • getTimezoneOffset: Returns the time-zone offset in minutes for the current locale.
  • getUTCDate: Returns the day (date) of the month in the specified date according to universal time.
  • getUTCDay: Returns the day of the week in the specified date according to universal time.
  • getUTCFullYear: Returns the year in the specified date according to universal time.
  • getUTCHours: Returns the hours in the specified date according to universal time.
  • getUTCMilliseconds: Returns the milliseconds in the specified date according to universal time.
  • getUTCMinutes: Returns the minutes in the specified date according to universal time.
  • getUTCMonth: Returns the month in the specified date according to universal time.
  • getUTCSeconds: Returns the seconds in the specified date according to universal time.
  • getYear {{template.Deprecated_inline()}} : Returns the year in the specified date according to local time. Use getFullYear instead.
  • setDate: Sets the day of the month for a specified date according to local time.
  • setFullYear: Sets the full year for a specified date according to local time.
  • setHours: Sets the hours for a specified date according to local time.
  • setMilliseconds: Sets the milliseconds for a specified date according to local time.
  • setMinutes: Sets the minutes for a specified date according to local time.
  • setMonth: Sets the month for a specified date according to local time.
  • setSeconds: Sets the seconds for a specified date according to local time.
  • setTime: Sets the value of the Date object according to local time.
  • setUTCDate: Sets the day of the month for a specified date according to universal time.
  • setUTCFullYear: Sets the full year for a specified date according to universal time.
  • setUTCHours: Sets the hour for a specified date according to universal time.
  • setUTCMilliseconds: Sets the milliseconds for a specified date according to universal time.
  • setUTCMinutes: Sets the minutes for a specified date according to universal time.
  • setUTCMonth: Sets the month for a specified date according to universal time.
  • setUTCSeconds: Sets the seconds for a specified date according to universal time.
  • setYear {{template.Deprecated_inline()}} : Sets the year for a specified date according to local time. Use setFullYear instead.
  • toGMTString {{template.Deprecated_inline()}}: Converts a date to a string, using the Internet GMT conventions. Use toUTCString instead.
  • toLocaleString: Converts a date to a string, using the current locale's conventions. Overrides the Object.toLocaleString method.
  • toLocaleDateString: Returns the "date" portion of the Date as a string, using the current locale's conventions.
  • toLocaleTimeString: Returns the "time" portion of the Date as a string, using the current locale's conventions.
  • toSource: Returns an object literal representing the specified Date object; you can use this value to create a new object. Overrides the Object.toSource method.
  • toString: Returns a string representing the specified Date object. Overrides the Object.toString method.
  • toUTCString: Converts a date to a string, using the universal time convention.
  • valueOf: Returns the primitive value of a Date object. Overrides the Object.valueOf method.

In addition, this object inherits the watch and unwatch methods from Object.

예제

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

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

today = new Date();
birthday = new Date("December 17, 1995 03:24:00");
birthday = new Date(95,11,17);
birthday = new Date(95,11,17,3,24,0);

Example: Calculating elapsed time

The following examples show how to determine the elapsed time between two dates:

// using static methods
var start = Date.now();
// the event you'd like to time goes here:
doSomethingForALongTime();
var end = Date.now();
var elapsed = end - start; // time in milliseconds
// if you have Date objects
var start = new Date();
// the event you'd like to time goes here:
doSomethingForALongTime();
var end = new Date();
var elapsed = end.getTime() - start.getTime(); // time in milliseconds
{{ wiki.languages( { "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Date" } ) }}

리비전 소스

<h3 name=".EC.9A.94.EC.95.BD"> 요약 </h3>
<p><b>기본 객체</b>
</p><p>Lets you work with dates and times.
</p>
<h3 name=".EC.83.9D.EC.84.B1"> 생성 </h3>
<p><code>Date</code> 객체는 다음과 같이 생성한다:
</p>
<pre class="eval">new Date()
new Date(<i>milliseconds</i>)
new Date(<i>dateString</i>)
new Date(<i>yr_num</i>, <i>mo_num</i>, <i>day_num</i>
        [, <i>hr_num</i>, <i>min_num</i>, <i>sec_num</i>, <i>ms_num</i>])
</pre>
<p><br>
JavaScript 1.3 이전 버전은 다음과 같다:
</p>
<pre class="eval">new Date()
new Date(<i>milliseconds</i>)
new Date(<i>dateString</i>)
new Date(<i>yr_num</i>, <i>mo_num</i>, <i>day_num</i>[, <i>hr_num</i>, <i>min_num</i>, <i>sec_num</i>])
</pre>
<h3 name=".ED.8C.8C.EB.9D.BC.EB.AF.B8.ED.84.B0"> 파라미터 </h3>
<dl><dt> <code>milliseconds</code> </dt><dd> Integer value representing the number of milliseconds since 1 January 1970 00:00:00.
</dd></dl>
<dl><dt> <code>dateString</code> </dt><dd> String value representing a date. The string should be in a format recognized by the <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/parse">parse</a> method.
</dd></dl>
<dl><dt> <code>yr_num, mo_num, day_num</code> </dt><dd> Integer values representing part of a date. As an integer value, the month is represented by 0 to 11 with 0=January and 11=December.
</dd></dl>
<dl><dt> <code>hr_num, min_num, sec_num, ms_num</code> </dt><dd> Integer values representing part of a date.
</dd></dl>
<h3 name=".EC.84.A4.EB.AA.85"> 설명 </h3>
<p>If you supply no arguments, the constructor creates a <code>Date</code> object for today's date and time according to local time. If you supply some arguments but not others, the missing arguments are set to 0. If you supply any arguments, you must supply at least the year, month, and day. You can omit the hours, minutes, seconds, and milliseconds.
</p><p>The date is measured in milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.
</p><p>The <code>Date</code> object provides uniform behavior across platforms.
</p><p>The <code>Date</code> object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.
</p><p>For compatibility with millennium calculations (in other words, to take into account the year 2000), you should always specify the year in full; for example, use 1998, not 98. To assist you in specifying the complete year, JavaScript includes the methods <code><a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getFullYear">getFullYear</a></code>, <code><a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setFullYear">setFullYear</a></code>, <code><a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCFullYear">getUTCFullYear</a></code>, and <code><a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setUTCFullYear">setUTCFullYear</a></code>.
</p><p>아래 예제는 <code>timeA</code>와 <code>timeB</code>의 시간차를 밀리초 단위로 반환합니다.
</p>
<pre class="eval">timeA = new Date();
// Statements here to take some action.
timeB = new Date();
timeDifference = timeB - timeA;
</pre>
<h3 name=".ED.95.98.EC.9C.84_.ED.98.B8.ED.99.98.EC.84.B1"> 하위 호환성 </h3>
<h4 name="JavaScript_1.2_.EC.9D.B4.ED.95.98_.EB.B2.84.EC.A0.84"> JavaScript 1.2 이하 버전 </h4>
<p><code>Date</code> 객체는 다음과 같이 동작합니다:
</p>
<ul><li> 1970년 이전의 날짜는 불가능합니다.
</li></ul>
<ul><li> JavaScript depends on platform-specific date facilities and behavior; the behavior of the <code>Date</code> object varies from platform to platform.
</li></ul>
<ul><li> The getDay and getUTCDay methods behave differently on differently localized platforms (e.g. a British and a German Windows). Specifically, 0 (zero) can be returned either for Sunday or Monday.
</li></ul>
<h3 name=".EC.86.8D.EC.84.B1"> 속성 </h3>
<ul><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/constructor">constructor</a>: 객체의 프로토타입을 생성하는 함수
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/prototype">prototype</a>: <code>Date</code> 객체에 추가 속성을 부여할 수 있다.
</li></ul>
<h3 name=".EC.A0.95.EC.A0.81_.EB.A9.94.EC.86.8C.EB.93.9C"> 정적 메소드 </h3>
<ul><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/now">now</a>: Returns the numeric value corresponding to the current time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/parse">parse</a>: Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00, local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/UTC">UTC</a>: Accepts the same parameters as the longest form of the constructor, and returns the number of milliseconds in a <code>Date</code> object since January 1, 1970, 00:00:00, universal time.
</li></ul>
<h3 name=".EB.A9.94.EC.86.8C.EB.93.9C"> 메소드 </h3>
<ul><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getDate">getDate</a>: 한달의 몇번째 날인지 반환
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getDay">getDay</a>: 주중의 몇번째 요일인지 반환
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getFullYear">getFullYear</a>: Returns the year of the specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getHours">getHours</a>: Returns the hour in the specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getMilliseconds">getMilliseconds</a>: Returns the milliseconds in the specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getMinutes">getMinutes</a>: Returns the minutes in the specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getMonth">getMonth</a>: Returns the month in the specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getSeconds">getSeconds</a>: Returns the seconds in the specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getTime">getTime</a>: Returns the numeric value corresponding to the time for the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getTimezoneOffset">getTimezoneOffset</a>: Returns the time-zone offset in minutes for the current locale.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCDate">getUTCDate</a>: Returns the day (date) of the month in the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCDay">getUTCDay</a>: Returns the day of the week in the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCFullYear">getUTCFullYear</a>: Returns the year in the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCHours">getUTCHours</a>: Returns the hours in the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCMilliseconds">getUTCMilliseconds</a>: Returns the milliseconds in the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCMinutes">getUTCMinutes</a>: Returns the minutes in the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCMonth">getUTCMonth</a>: Returns the month in the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getUTCSeconds">getUTCSeconds</a>: Returns the seconds in the specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getYear">getYear</a> {{template.Deprecated_inline()}} : Returns the year in the specified date according to local time. Use <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/getFullYear">getFullYear</a> instead.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setDate">setDate</a>: Sets the day of the month for a specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setFullYear">setFullYear</a>: Sets the full year for a specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setHours">setHours</a>: Sets the hours for a specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setMilliseconds">setMilliseconds</a>: Sets the milliseconds for a specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setMinutes">setMinutes</a>: Sets the minutes for a specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setMonth">setMonth</a>: Sets the month for a specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setSeconds">setSeconds</a>: Sets the seconds for a specified date according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setTime">setTime</a>: Sets the value of the <code>Date</code> object according to local time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setUTCDate">setUTCDate</a>: Sets the day of the month for a specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setUTCFullYear">setUTCFullYear</a>: Sets the full year for a specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setUTCHours">setUTCHours</a>: Sets the hour for a specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setUTCMilliseconds">setUTCMilliseconds</a>: Sets the milliseconds for a specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setUTCMinutes">setUTCMinutes</a>: Sets the minutes for a specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setUTCMonth">setUTCMonth</a>: Sets the month for a specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setUTCSeconds">setUTCSeconds</a>: Sets the seconds for a specified date according to universal time.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setYear">setYear</a> {{template.Deprecated_inline()}} : Sets the year for a specified date according to local time. Use <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/setFullYear">setFullYear</a> instead.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/toGMTString">toGMTString</a> {{template.Deprecated_inline()}}: Converts a date to a string, using the Internet GMT conventions. Use <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/toUTCString">toUTCString</a> instead.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/toLocaleString">toLocaleString</a>: Converts a date to a string, using the current locale's conventions. Overrides the <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Object/toLocaleString">Object.toLocaleString</a> method.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/toLocaleDateString">toLocaleDateString</a>: Returns the "date" portion of the Date as a string, using the current locale's conventions.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/toLocaleTimeString">toLocaleTimeString</a>: Returns the "time" portion of the Date as a string, using the current locale's conventions.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/toSource">toSource</a>: Returns an object literal representing the specified <code>Date</code> object; you can use this value to create a new object.  Overrides the <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Object/toSource">Object.toSource</a> method.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/toString">toString</a>: Returns a string representing the specified <code>Date</code> object.  Overrides the <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Object/toString">Object.toString</a> method.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/toUTCString">toUTCString</a>: Converts a date to a string, using the universal time convention.
</li><li> <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Date/valueOf">valueOf</a>: Returns the primitive value of a <code>Date</code> object.  Overrides the <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Object/valueOf">Object.valueOf</a> method.
</li></ul>
<p>In addition, this object inherits the <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Object/watch">watch</a> and <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Object/unwatch">unwatch</a> methods from <a href="ko/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a>.
</p>
<h3 name=".EC.98.88.EC.A0.9C"> 예제 </h3>
<h4 name=".EC.98.88.EC.A0.9C:_.EB.82.A0.EC.A7.9C.EB.A5.BC_.EC.A7.80.EC.A0.95.ED.95.98.EB.8A.94_.EC.97.AC.EB.9F.AC.EA.B0.80.EC.A7.80_.EB.B0.A9.EB.B2.95"> 예제: 날짜를 지정하는 여러가지 방법 </h4>
<p>아래 예제는 날짜를 지정하는 몇가지 방법을 보여줍니다:
</p>
<pre class="eval">today = new Date();
birthday = new Date("December 17, 1995 03:24:00");
birthday = new Date(95,11,17);
birthday = new Date(95,11,17,3,24,0);
</pre>
<h4 name="Example:_Calculating_elapsed_time"> Example: Calculating elapsed time </h4>
<p>The following examples show how to determine the elapsed time between two dates:
</p>
<pre class="eval">// using static methods
var start = Date.now();
// the event you'd like to time goes here:
doSomethingForALongTime();
var end = Date.now();
var elapsed = end - start; // time in milliseconds
</pre>
<pre class="eval">// if you have Date objects
var start = new Date();
// the event you'd like to time goes here:
doSomethingForALongTime();
var end = new Date();
var elapsed = end.getTime() - start.getTime(); // time in milliseconds
</pre>{{ wiki.languages( { "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Date" } ) }}
Revert to this revision