程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi中修改時間的函數

Delphi中修改時間的函數

編輯:Delphi

RecodeDateTime、RecodeDate、RecodeTime、RecodeYear ... 修改時間

DateUtils.RecodeDateTime();
DateUtils.RecodeDate();
DateUtils.RecodeTime();
DateUtils.RecodeYear();
DateUtils.RecodeMonth();
DateUtils.RecodeDay();
DateUtils.RecodeHour();
DateUtils.RecodeMinute();
DateUtils.RecodeSecond();
DateUtils.RecodeMilliSecond();
DateUtils.TryRecodeDateTime();

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

type
 TForm1 = class(TForm)
  procedure FormCreate(Sender: TObject);
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

uses DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
const
 st = 'yyyy-m-d h:n:s:z';
var
 t1, t2: TDateTime;
begin
 t1 := EncodeDateTime(2001, 1, 1, 1, 1, 1, 1);

 t2 := RecodeDateTime(t1, 2009, 5, 21, 11, 22, 33, 999);
 ShowMessage(FormatDateTime(st, t2));  //2009-5-21 11:22:33:999

 t2 := RecodeDate(t1, 2009, 5, 21);
 ShowMessage(FormatDateTime(st, t2));  //2009-5-21 1:1:1:1

 t2 := RecodeTime(t1, 11, 22, 33, 999);
 ShowMessage(FormatDateTime(st, t2));  //2009-1-1 11:22:33:999

 t2 := RecodeYear(t1, 2009);
 ShowMessage(FormatDateTime(st, t2));  //2009-1-1 1:1:1:1

 t2 := RecodeMonth(t1, 5);
 ShowMessage(FormatDateTime(st, t2));  //2001-5-1 1:1:1:1

 t2 := RecodeDay(t1, 21);
 ShowMessage(FormatDateTime(st, t2));  //2001-1-21 1:1:1:1

 t2 := RecodeHour(t1, 11);
 ShowMessage(FormatDateTime(st, t2));  //2001-1-1 11:1:1:1

 t2 := RecodeMinute(t1, 22);
 ShowMessage(FormatDateTime(st, t2));  //2001-1-1 1:22:1:1

 t2 := RecodeSecond(t1, 33);
 ShowMessage(FormatDateTime(st, t2));  //2001-1-1 1:1:33:1

 t2 := RecodeMilliSecond(t1, 999);
 ShowMessage(FormatDateTime(st, t2));  //2001-1-1 1:1:1:999

 if TryRecodeDateTime(t1, 2009, 5, 21, 11, 22, 33, 999, t2) then
  ShowMessage(FormatDateTime(st, t2));  //2009-5-21 11:22:33:999
end;

end.

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