怎么算得一个比某个时间多N分钟的TDateTime

DelisPhi 2010-05-28 08:26:45
比如,在2009-1-1 18:00:00.000 加15分钟,返回2009-1-1 18:15:00.000,依此类推。
...全文
35 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
DelisPhi 2010-05-29
  • 打赏
  • 举报
回复
IncMinute啊,谢谢哦!
hongss 2010-05-28
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(DateTimeToStr(IncMinute(now,15)));
end;
ron_xin 2010-05-28
  • 打赏
  • 举报
回复
IncMinute( ) 就是分钟加减
ron_xin 2010-05-28
  • 打赏
  • 举报
回复
Delphi里有现成的函数可以实现日期加减,在DateUtils单元里的。



function IncYear(const AValue: TDateTime;

const ANumberOfYears: Integer = 1): TDateTime;

// function IncMonth is in SysUtils

function IncWeek(const AValue: TDateTime;

const ANumberOfWeeks: Integer = 1): TDateTime;

function IncDay(const AValue: TDateTime;

const ANumberOfDays: Integer = 1): TDateTime;

function IncHour(const AValue: TDateTime;

const ANumberOfHours: Int64 = 1): TDateTime;

function IncMinute(const AValue: TDateTime;

const ANumberOfMinutes: Int64 = 1): TDateTime;

function IncSecond(const AValue: TDateTime;

const ANumberOfSeconds: Int64 = 1): TDateTime;

function IncMilliSecond(const AValue: TDateTime;

const ANumberOfMilliSeconds: Int64 = 1): TDateTime;
mingxuan0714 2010-05-28
  • 打赏
  • 举报
回复
tdatetime其实就是double,1表示1天,因此1分钟就是1/(24×60)
加N分钟就把时间加上N/(24×60)
Frank.WU 2010-05-28
  • 打赏
  • 举报
回复
2009-1-1 18:00:00.000 := 2009-1-1 18:00:00.000 + 5分钟;{对,就这么简单,不过需要将类型转换一下}

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧