zoukankan      html  css  js  c++  java
  • 分享一个求时间差大于多少秒的函数

    function YearsBetween(const ANow, AThen: TDateTime): Integer;//返回两个日期间隔的年数
    function MonthsBetween(const ANow, AThen: TDateTime): Integer;//返回两个日期间隔的月数
    function WeeksBetween(const ANow, AThen: TDateTime): Integer;//返回两个日期间隔的星期数
    function DaysBetween(const ANow, AThen: TDateTime): Integer;//返回两个日期间隔的天数
    function HoursBetween(const ANow, AThen: TDateTime): Int64;//返回两个日期间隔的小时数
    function MinutesBetween(const ANow, AThen: TDateTime): Int64;//返回两个日期间隔的分钟数
    function SecondsBetween(const ANow, AThen: TDateTime): Int64;//返回两个日期间隔的秒数
    function MilliSecondsBetween(const ANow, AThen: TDateTime): Int64;//返回两个日期间隔的毫秒数

    单元System.DateUtils还提供了其他大量实用的日期类型的函数,感兴趣可以参考。

    现在实现时间差大于多少秒的函数:

    unit Unit2;
    
    interface
    
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
      FMX.Controls.Presentation, FMX.StdCtrls,system.dateutils;
    
    type
      TForm2 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        function CompareSeconds(ANow,AThen:TDateTime;aSec:Integer):Boolean;
      end;
    
    var
      Form2: TForm2;
    
    implementation
    
    {$R *.fmx}
    
    procedure TForm2.Button1Click(Sender: TObject);
    var
      d1,d2:TDateTime;
      d:double;
    begin
      d1:=now;
      d2:=now-1;
    //  d:=(d1-d2)*24*60*60;//将时间差转换成秒数
      if CompareSeconds(d1,d2,60) then
         ShowMessage('ok');
    
    end;
    
    
    function TForm2.CompareSeconds(ANow, AThen: TDateTime; aSec: Integer): Boolean;
    begin
         result:= SecondsBetween(ANow,AThen)>=aSec;
    end;
    
    end.

    再次强调,Delphi为我们做了大量处理日期的函数,涉及到这方面的代码,一定不要自己造轮子,直接去System.DateUtils单元去找找。

  • 相关阅读:
    iOS开发tips-UITableView、UICollectionView行高/尺寸自适应
    10559
    日志系统之基于Zookeeper的分布式协同设计
    IOS 图片上传处理 图片压缩 图片处理
    istream, outstream使用及常见错误
    matlab 扩大虚拟内存
    github不小心同步覆盖了本地文件
    经典统计语言模型
    Makefile 快速入门
    word2vec——高效word特征提取
  • 原文地址:https://www.cnblogs.com/kinglandsoft/p/10620680.html
Copyright © 2011-2022 走看看