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

YearsBetween、MonthsBetween ... YearSpan、MonthSpan ... 間隔時間

編輯:Delphi

DateUtils.YearsBetween();
DateUtils.MonthsBetween();
DateUtils.WeeksBetween();
DateUtils.DaysBetween();
DateUtils.HoursBetween();
DateUtils.MinutesBetween();
DateUtils.SecondsBetween();
DateUtils.MilliSecondsBetween();
DateUtils.YearSpan();
DateUtils.MonthSpan();
DateUtils.WeekSpan();
DateUtils.DaySpan();
DateUtils.HourSpan();
DateUtils.MinuteSpan();
DateUtils.SecondSpan();
DateUtils.MilliSecondSpan();

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
t1,t2: TDateTime;
i: Int64;
d: Double;
begin
t1 := StrToDateTime('2009-5-20 11:22:33');
t2 := StrToDateTime('2020-9-21 22:33:44');
i := YearsBetween(t1, t2); //11
i := MonthsBetween(t1, t2); //136
i := WeeksBetween(t1, t2); //591
i := DaysBetween(t1, t2); //4142
i := HoursBetween(t1, t2); //99419
i := MinutesBetween(t1, t2); //5965151
i := SecondsBetween(t1, t2); //357909071
i := MilliSecondsBetween(t1, t2); //357909070999
i := YearsBetween(t2, t1); //11, 參數無先後
{下面這個系列返回的時間間隔是 Double 類型的, 更精確}
d := YearSpan(t1, t2); //11.3414540712855
d := MonthSpan(t1, t2); //136.097448855426
d := WeekSpan(t1, t2); //591.780871362434
d := DaySpan(t1, t2); //4142.46609953704
d := HourSpan(t1, t2); //99419.1863888889
d := MinuteSpan(t1, t2); //5965151.18333333
d := SecondSpan(t1, t2); //357909071
d := MilliSecondSpan(t1, t2); //357909071000
end;
end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved