delphi 间隔时间


本文整理自网络,侵删。

 delphi YearsBetween、MonthsBetween … YearSpan、MonthSpan … 间隔时间

DateUtils.YearsBetween();
DateUtils.MonthsBetween();
DateUtils.WeeksBetween();
DateUtils.DaysBetween();
DateUtils.HoursBetween();
DateUtils.MinutesBetween();
DateUtils.SecondsBetween();
DateUtils.MilliSecondsBetween();

DateUtils.YearSpan();
DateUtils.MonthSpan();
DateUtils.WeekSpan();
DateUtils.DaySpan();
DateUtils.HourSpan();
DateUtils.MinuteSpan();
DateUtils.SecondSpan();
DateUtils.MilliSecondSpan();

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

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;
  i: Int64;
  d: Double;
begin
  t1 := StrToDateTime('2009-5-20 11:22:33');
  t2 := StrToDateTime('2020-9-21 22:33:44');

  i := YearsBetween(t1, t2);        //11
  i := MonthsBetween(t1, t2);       //136
  i := WeeksBetween(t1, t2);        //591
  i := DaysBetween(t1, t2);         //4142
  i := HoursBetween(t1, t2);        //99419
  i := MinutesBetween(t1, t2);      //5965151
  i := SecondsBetween(t1, t2);      //357909071
  i := MilliSecondsBetween(t1, t2); //357909070999

  i := YearsBetween(t2, t1);        //11, 参数无先后

  {下面这个系列返回的时间间隔是 Double 类型的, 更精确}
  d := YearSpan(t1, t2);        //11.3414540712855
  d := MonthSpan(t1, t2);       //136.097448855426
  d := WeekSpan(t1, t2);        //591.780871362434
  d := DaySpan(t1, t2);         //4142.46609953704
  d := HourSpan(t1, t2);        //99419.1863888889
  d := MinuteSpan(t1, t2);      //5965151.18333333
  d := SecondSpan(t1, t2);      //357909071
  d := MilliSecondSpan(t1, t2); //357909071000
end;

end.

相关阅读 >>

Delphi 判断目录是否存在,不存在则创建目录并打开,存在则直接打开

Delphi2010 关于record类型rtti反射的用途和方法

Delphi 判断 文本文件 utf-8 bom头

Delphi的四舍五入函数

Delphi 解决idtcpclient和idtcpserver通信中文乱码问题

Delphi 简单播放mp3

Delphi 的内存操作函数(6): 跨进程的内存分配

download 和 http downloader 源码

Delphi 超短精简进制转换

Delphi从路径取得文件名的简易方法

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



打赏

取消

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

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

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

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

评论

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