Delphi判断时间范围  
官方Delphi 学习QQ群: 682628230(三千人)
频道

Delphi判断时间范围


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.


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.052228927612305 seconds