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.

posted on   滔Roy  阅读(659)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报

导航

点击右上角即可分享
微信分享提示