如何在日期时间变量中增加天数和小时数? [英] How to add days and hours to a date-time variable?

查看:107
本文介绍了如何在日期时间变量中增加天数和小时数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我需要获取类似 12/30/2013 的日期并在晚上8点添加10天,如果我有<$ c,如何在Delphi中做到这一点$ c> TDateTime 变量是第一个日期?

If I need to get a date like 12/30/2013 and add 10 days at 8pm, How can I do that in Delphi if I have a TDateTime variable with that first date?

推荐答案

您可以使用 + 运算符添加整数天数,然后使用 SysUtils.ReplaceTime()更改时间,例如:

You can use the + operator to add an integral number of days, and use SysUtils.ReplaceTime() to change the time, eg:

uses
  ..., SysUtils;

var
  DT: TDateTime;
begin
  DT := EncodeDate(2013, 12, 30); // Dec 30 2013 @ 12AM
  DT := DT + 10; // Jan 9 2014 @ 12AM
  ReplaceTime(DT, EncodeTime(20, 0, 0, 0)); // Jan 9 2014 @ 8PM
end;

这篇关于如何在日期时间变量中增加天数和小时数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆