WithinPastYears、WithinPastMonths、WithinPastWeeks、WithinPastDays ... 判斷兩個時間差是否在一個指定范圍內
DateUtils.WithinPastYears();
DateUtils.WithinPastMonths();
DateUtils.WithinPastWeeks();
DateUtils.WithinPastDays();
DateUtils.WithinPastHours();
DateUtils.WithinPastMinutes();
DateUtils.WithinPastSeconds();
DateUtils.WithinPastMilliSeconds();
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;
b: Boolean;
begin
t1 := StrToDateTime('2009-5-20 11:22:33');
t2 := StrToDateTime('2009-5-21 11:22:33');
{兩個時間差是否在 24 年內}
b := WithinPastYears(t1, t2, 24); //True
{兩個時間差是否在 24 個月內}
b := WithinPastMonths(t1, t2, 24); //True
{兩個時間差是否在 24 個周內}
b := WithinPastWeeks(t1, t2, 24); //True
{兩個時間差是否在 24 天內}
b := WithinPastDays(t1, t2, 24); //True
{兩個時間差是否在 24 個小時內}
b := WithinPastHours(t1, t2, 24); //True
{兩個時間差是否在 24 分鐘內}
b := WithinPastMinutes(t1, t2, 24); //False
{兩個時間差是否在 24 秒內}
b := WithinPastSeconds(t1, t2, 24); //False
{兩個時間差是否在 24 毫秒內}
b := WithinPastMilliSeconds(t1, t2, 24); //False
// ShowMessage(BoolToStr(b, True));
end;
end.