------------------------------------------
Date and time routines 日期及时间函数
------------------------------------------
Date 传回目前的日期
Unit SysUtils
函数原型 function Date: TDateTime;
范例 procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := 'Today is ' + DateToStr(Date);
end;
------------------------------------------
DateTimeToStr 日期时间转换成内定型字串(1996/12/20 09:12:20 PM)
------------------------------------------
Unit SysUtils
函数原型 function DateTimeToStr(DateTime: TDateTime): string;
范例 procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := DateTimeToStr(Now);
end;
--------------------------------------------------------
DateTimeToString 日期时间转换成自定型字串
-------------------------------------------------------
Unit SysUtils
函数原型 procedure DateTimeToString(var Result: string; const Format:
string; DateTime: TDateTime);
范例 procedure TForm1.FormCreate(Sender: TObject);
var
s:string;
begin
DateTimeToString(s,'dddd,mmmm d,yyyy "at" hh:mm
AM/PM',Now);
Label1.Caption :=s;
end;
结果 星期五,十二月 20,1996 at 09:20 PM
-----------------------------------------------------------------------------
**** Format格式叁考下面.FormatDateTime.
--------------------------------------------------------
DateToStr 日期转换成内定型字串.(1996/12/20)
--------------------------------------------------------
Unit SysUtils
函数原型 function DateToStr(Date: TDateTime): string;
范例
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := 'Today is ' + DateToStr(Date);
end;
# Date, DateToStr Example
--------------------------------------------------------
DayOfWeek 求叁数日期是星期几.
--------------------------------------------------------
Unit SysUtils
函数原型 function DayOfWeek(Date: TDateTime): Integer;
说明 传回值是一整数,1~7.
星期日为1.
范例
procedure TForm1.Button1Click(Sender: TObject);
var
ADate: TDateTime;
days: array[1..7] of string;
begin
days[1] := 'Sunday';
days[2] := 'Monday';
days[3] := 'Tuesday';
days[4] := 'Wednesday';
days[5] := 'Thursday';
days[6] := 'Friday';
days[7] := 'Saturday';
ADate := StrToDate(Edit1.Text);
ShowMessage(Edit1.Text + ' is a ' + days[DayOfWeek(ADate)];
end;
# StrToDate, DayOfWeek Example
--------------------------------------------------------
DecodeDate 将TDateTime型态的日期变数,转为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;
# DecodeDate, DecodeTime Example