Delphi 日期函数的单元 DateUtils

 

Delphi DecodeDate和EncodeDate 拆分和聚合时间函数的用法  

 

SysUtils
procedure DecodeData(Date: TDateTime; var Year, Month, Day: Word);
DecodeDate打断TdateTime成为年月日的值。
DecodeDate打断由Date参数说明的值成为年月日的值。
如果TDateTime值是小于或等于0,那么返回的年月日值为0;

这个例子使用一个按纽和两个标签,当按击按钮时,当前的日期和时间就会出现在两个标签的标题中显示。
procedure TForm1.Button1Click(Sender: TObject);
var
  Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present := Now;
DecodeDate(Present, Year, Hour, 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;

 

 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;
procedure   TForm1.Button1Click(Sender:   TObject);
var
    MyDate:   TDateTime;
begin
    MyDate   :=   EncodeDate(StrToInt(Edit1.Text),   StrToInt(Edit2.Text),   StrToInt(Edit3.Text)); 
    Label1.Caption   :=   DateToStr(MyDate);
end;

 

posted @ 2013-05-20 21:50  万大侠  阅读(223)  评论(0编辑  收藏  举报