2009. 12. 1. 16:41

TDateTime형 - 3

관련 함수와 프로시져-02

델파이에서 제공하는 TDateTime 관련 함수와 프로시져 중에는 기본적인 변환을 위한 것 이외에도 아래와 같은 것들이 있다.

◇ DayOfWeek : 일부터 토까지의 요일문자열을 반환한다. (인자/1:일-7:토)
function DayOfWeek(Date: TDateTime): Integer;
procedure TForm1.Button1Click(Sender: TObject);
var
ADate: TDateTime;
begin
ADate := StrToDate(Edit1.Text);
Label1.Caption := 'Day ' + IntToStr(DayOfWeek(ADate)) + ' of the
week';
end;

◇ DecodeDate : 일자를 Year, Month, Day로 변환한다.
이 때, Year에 1-9999, Month에 1-12, Day에 28, 29, 30, 31가 들어감.
procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
procedure TForm1.Button1Click(Sender: TObject);
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) +
' of Hour ' + IntToStr(Hour);
end;

◇ EncodeDate : 인자 Year, Month, Day로 TDateTime형을 반환한다.
이 때, Year는 1-9999, Month는 1-12, Day는 28, 29, 30, 31가 들어감
function EncodeDate(Year, Month, Day: Word): TDateTime;
procedure TForm1.Button1Click(Sender: TObject);
var
MyDate: TDateTime;
begin
MyDate := EncodeDate(83, 12, 31);
Label1.Caption := DateToStr(MyDate);
end;

◇ DecodeTime : 시간을 Hour, Min, Sec, MSec으로 변환한다.
이 때, Hour에는 0-23, Min, Sec에는 0-59, MSec에는 0-999의 값이 반환됨.
procedure DecodeTime(Time: TDateTime;
var Hour, Min, Sec, MSec: Word);
procedure TForm1.Button1Click(Sender: TObject);
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min)
+ ' of Hour ' + IntToStr(Hour);
end;

◇ EncodeTime : Hour, Min, Sec, MSec를 인자로 TDateTime형을 반환함.
이 때, Hour는 0-23, Min, Sec은 0-59, MSec은 0-999의 값 이용.
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
procedure TForm1.Button1Click(Sender: TObject);
var
MyTime: TDateTime;
begin
MyTime := EncodeTime(0, 45, 45, 7);
Label1.Caption := TimeToStr(MyTime);
end;

◇ DateTimeToFileDate : 델파이의 Date 포맷을 DOS용 Date 포맷으로 변환.
반환값은 FindFirst, FindNext에서 이용되는 TSearchRec.Time과 동일.
function DateTimeToFileDate(DateTime: TDateTime): Integer;

◇ DateTimeToFileDate : DOS용 Date 포맷을 Dephi용으로 변환.
FindFirst나 FindNext등을 이용하는 경우, TSearchRec.Time의 값과 동일.
인자는 FindFirst나 FindNext에서 이용되는 TSearchRec.Time과 동일.
function FileDateToDateTime(FileDate: Integer): TDateTime;

'Delphi' 카테고리의 다른 글

동적 체크박스 생성  (0) 2010.03.24
단축키 모음  (0) 2010.03.22
TDateTime형 - 2  (0) 2009.12.01
TDateTime형 - 1  (0) 2009.12.01
델파이의 데이터형  (0) 2009.11.24