delphi 判断两个时间差是否在一个指定范围内


本文整理自网络,侵删。

 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.

相关阅读 >>

Delphi读取excel文件-统计全部工作表中内容相同单元格出现次数

Delphi 转数字为大写金额源代码

Delphi adoquery判断插入的值是否重复

Delphi判断电脑连接到 internet 了吗?

Delphi统计字数(汉字+字母+符号)

Delphi产生不重复随机数的算法

Delphi读取webbrowse中的图片显示在image中

Delphi 移动端使用 sqlite数据库查询

Delphi xe5调用外部扫描程序――谷歌 zxing

Delphi for 循环 downto用法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...