您的代码没有任何问题。实际上,使用您显示的值,我无法重现您描述的问题。2020.09.30 08:32:21
正如预期的那样,我得到的输出是。
话虽如此,当这些问题得到修复时,已知该单元中的功能在DateUtils
XE 之前存在准确性问题。C++Builder 2009 早于 XE。因此,如果您无法升级到最新版本,您至少可以应用在更高版本中使用的相同修复:
#include <SysUtils.hpp>
namespace fixed {
TDateTime __fastcall IncSecond(const TDateTime AValue, const __int64 ANumberOfSeconds = 1)
{
TTimeStamp TS = DateTimeToTimeStamp(AValue);
double TempTime = TimeStampToMSecs(TS);
// if the above call to TimeStampToMSecs() proves to be inaccurate (it did
// in my test in C++, but worked fine in Delphi), you can use this instead:
// double TempTime = (double(TS.Date) * double(MSecsPerDay)) + double(TS.Time);
TempTime = TempTime + (ANumberOfSeconds * MSecsPerSec);
TS = MSecsToTimeStamp(TempTime);
return TimeStampToDateTime(TS);
}
}
TDateTime dt(2000,1,1,0,0,0,0);
AnsiString sdt = "";
DateTimeToString(sdt, "yyyy/mm/dd hh:nn:ss", dt);
closeDateTime = dt;
closeDateTime = fixed::IncSecond(closeDateTime,footer->secondsFromZeroDateOfFinishDocument);
DateTimeToString(sdt, "yyyy/mm/dd hh:nn:ss", closeDateTime);