本文整理自网络,侵删。
DateOf、TimeOf、YearOf、MonthOf、WeekOf、DayOf、HourOf、MinuteOf、SecondOf、MilliSecondOf - 提取时间成分
它们的参数都是一个 TDateTime,
DateOf、TimeOf 分别提取日期与时间, 并返回 TDateTime 类型;
YearOf、MonthOf、WeekOf、DayOf、HourOf、MinuteOf、SecondOf、MilliSecondOf 返回的都是 Word 类型.
--------------------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses DateUtils;
procedure TForm1.FormCreate(Sender: TObject);
var
dt,d,t: TDateTime;
Year,Month,Week,Day,Hour,Minute,Second,MilliSecond: Word;
begin
dt := StrToDateTime('2009-5-20 11:22:33');
d := DateOf(dt);
ShowMessage(DateToStr(d)); //2009-5-20
t := TimeOf(dt);
ShowMessage(TimeToStr(t)); //11:22:33
Year := YearOf(dt);
Month := MonthOf(dt);
Week := WeekOf(dt);
Day := DayOf(dt);
Hour := HourOf(dt);
Minute := MinuteOf(dt);
Second := SecondOf(dt);
MilliSecond := MilliSecondOf(dt);
ShowMessageFmt('%d,%d,%d,%d,%d,%d,%d,%d', [Year,Month,Week,Day,Hour,Minute,
Second,MilliSecond]); {2009,5,20,11,22,33,0}
end;
end.
相关阅读 >>
关于Delphi xe5 firemonkey 手机屏幕自适应程序问题
Delphi+access错误"不正常地定义参数对象。提供了不一致或不完整的信息。"
Delphi 10 seattle android应用程序使用toast
更多相关阅读请进入《Delphi》频道 >>