AI摘要

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

在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;



最后修改:2019 年 11 月 09 日
点赞的人是最酷的