程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> DateOf、TimeOf、YearOf、MonthOf、WeekOf、DayOf、HourOf、MinuteOf、SecondOf、MilliSecondOf - 提取時間成分

DateOf、TimeOf、YearOf、MonthOf、WeekOf、DayOf、HourOf、MinuteOf、SecondOf、MilliSecondOf - 提取時間成分

編輯:Delphi

它們的參數都是一個 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.


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved