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

Delphi中的增時函數

編輯:Delphi

IncYear、IncMonth、IncWeek、IncDay、IncHour、IncMinute、IncSecond、IncMilliSecond - 增時

DateUtils.IncYear();
DateUtils.IncMonth();
DateUtils.IncWeek();
DateUtils.IncDay();
DateUtils.IncHour();
DateUtils.IncMinute();
DateUtils.IncSecond();
DateUtils.IncMilliSecond();

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);
var
 t1,t2: TDateTime;
 i: Int64;
 d: Double;
begin
 t1 := StrToDateTime('2011-1-1 1:1:1');

 t2 := IncYear(t1);
 ShowMessage(DateTimeToStr(t2)); //2012-1-1 1:01:01

 t2 := IncYear(t1, 3);
 ShowMessage(DateTimeToStr(t2)); //2014-1-1 1:01:01

 t2 := IncMonth(t1);
 ShowMessage(DateTimeToStr(t2)); //2011-2-1 1:01:01

 t2 := IncWeek(t1);
 ShowMessage(DateTimeToStr(t2)); //2011-1-8 1:01:01

 t2 := IncDay(t1);
 ShowMessage(DateTimeToStr(t2)); //2011-1-2 1:01:01

 t2 := IncHour(t1);
 ShowMessage(DateTimeToStr(t2)); //2011-1-1 2:01:01

 t2 := IncMinute(t1);
 ShowMessage(DateTimeToStr(t2)); //2011-1-1 1:02:01

 t2 := IncSecond(t1);
 ShowMessage(DateTimeToStr(t2)); //2011-1-1 1:01:02

 t2 := IncMilliSecond(t1);
 ShowMessage(FormatDateTime('yyyy-m-d h:n:s:zzz', t2)); //2011-1-1 1:01:01:001
end;

end.

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