Delphi 日期加减函数

samool 发布暂无评论15163 阅读

AI摘要

Delphi 提供了 DateUtils 单元,其中包含多个日期时间操作函数,如 IncYear、IncWeek、IncDay、IncHour、IncMinute、IncSecond 和 IncMilliSecond,用于对 TDateTime 类型的日期进行年、月、日、小时、分钟、秒和毫秒的加减操作。这些函数通过简单的参数传递即可实现日期时间的调整。

在Delphi 中有一个date日期操作的函数库,直接引用系统单元DateUtils就可以了,里边有很多日期时间的操作函数,包含年份加减,月份加减,天数加减,小时加减,分钟加减,秒钟加减等,下面是这些函数的原型,直接调用函数就可以了。

function IncYear(const AValue: TDateTime;
  const ANumberOfYears: Integer): TDateTime;
begin
  Result := IncMonth(AValue, ANumberOfYears * MonthsPerYear);
end;

function IncWeek(const AValue: TDateTime;
  const ANumberOfWeeks: Integer): TDateTime;
begin
  Result := AValue + ANumberOfWeeks * DaysPerWeek;
end;

function IncDay(const AValue: TDateTime;
  const ANumberOfDays: Integer): TDateTime;
begin
  Result := AValue + ANumberOfDays;
end;

function IncHour(const AValue: TDateTime;
  const ANumberOfHours: Int64): TDateTime;
begin
  Result := ((AValue * HoursPerDay) + ANumberOfHours) / HoursPerDay;
end;

function IncMinute(const AValue: TDateTime;
  const ANumberOfMinutes: Int64): TDateTime;
begin
  Result := ((AValue * MinsPerDay) + ANumberOfMinutes) / MinsPerDay;
end;

function IncSecond(const AValue: TDateTime;
  const ANumberOfSeconds: Int64): TDateTime;
begin
  Result := ((AValue * SecsPerDay) + ANumberOfSeconds) / SecsPerDay;
end;

function IncMilliSecond(const AValue: TDateTime;
  const ANumberOfMilliSeconds: Int64): TDateTime;
begin
  Result := ((AValue * MSecsPerDay) + ANumberOfMilliSeconds) / MSecsPerDay;
end;

  1. 01Golang 汇编入门知识总结2020-09-27
  2. 02用了多年的自动升级小工具《KDBOSS升级助手》2020-06-17
  3. 03MSSQL日期代码格式2014-03-01
  4. 04Delphi获得与设置系统时间格式 2014-02-24
  5. 05c#的DateTime.Now函数详解2013-12-31
  6. 06SQL日期和时间函数2009-04-13
  7. 07SQL将日期按天分类统计2008-06-12
  8. 08SaMDeditor V2.4 更新内容2026-12-02
  9. 09恭喜《轻武爱学习》小程序备案成功!2026-11-24
  10. 10SaView 图阅 1.1.1 更新日志2026-11-18
COMMENTS / 一纸留言

读者留言 0 条

一纸留言,便是山水间的一次相逢。

还没有留言,欢迎写下第一段交流。

WRITE A COMMENT

写下你的留言