JScript Date 개체

JScript Date 개체는 임의의 날짜 및 시간 표시, 현재 시스템 시간 파악, 날짜 간의 차이 계산에 사용할 수 있습니다. Date 개체에는 미리 정의된 속성과 메서드가 몇 가지 있습니다. Date 개체는 요일, 월, 일 및 연도의 날짜와 시, 분, 초 및 밀리초의 시간을 저장합니다. 이 정보는 1970년 1월 1일, 그리니치 표준시로 알려진 UTC(지역 표준시) 00:00:00.000시 이후의 밀리초 수를 기반으로 한 것입니다. JScript에서는 대략 250,000 B.C.부터 255,000 A.D. 범위에 있는 날짜를 처리할 수 있습니다. 그러나 일부 형식 기능은 0 A.D.부터 9999 A.D 범위의 날짜만 지원합니다.

Date 개체 만들기

새 Date 개체를 만들려면 new 연산자를 사용합니다. 다음 예제에서는 현재 연도에서 지나간 일 수와 남아 있는 일 수를 계산합니다.

// Get the current date and read the year.
var today : Date = new Date();
// The getYear method should not be used. Always use getFullYear.
var thisYear : int = today.getFullYear();

// Create two new dates, one for January first of the current year,
// and one for January first of next year. The months are numbered
// starting with zero.
var firstOfYear : Date = new Date(thisYear,0,1);
var firstOfNextYear : Date = new Date(thisYear+1,0,1);

// Calculate the time difference (in milliseconds) and 
// convert the differnce to days.
const millisecondsToDays = 1/(1000*60*60*24);
var daysPast : double = (today - firstOfYear)*millisecondsToDays;
var daysToGo : double = (firstOfNextYear - today)*millisecondsToDays;

// Display the information.
print("Today is: "+today+".");
print("Days since first of the year: "+Math.floor(daysPast));
print("Days until the end of the year: "+Math.ceil(daysToGo));

이 프로그램은 다음과 비슷한 결과를 출력합니다.

Today is: Sun Apr 1 09:00:00 PDT 2001.
Days since first of the year: 90
Days until the end of the year: 275

참고 항목

참조

Date 개체

기타 리소스

내장 개체