我必须将我的本地日期和时间与从数据库返回的相同日期和时间同步。
sql:
select first 1 CURRENT_TIMESTAMP from RDB$DATABASE
此 SQL 命令返回数据库服务器上的当前日期和时间。
现在,我需要缓存它并根据本地差异提供正确的时间。问题是可以再次更改本地日期和时间。
如何在不再次执行 SQL 的情况下保证正确的日期时间?
我找到了一个解决方案:
var
SQLTimestamp: TDateTime=0;
LocalTimestamp: TDateTime=0;
function SysUpTime : TDateTime;
var
Count, Freq : int64;
begin
QueryPerformanceCounter(count);
QueryPerformanceFrequency(Freq);
if (count<> 0) and (Freq <> 0) then
begin
Result := Count / Freq;
Result := result / SecsPerDay;
end
else
Result := 0;
end;
function RealTime: TDateTime;
var
queryTime, dbTime: tdatetime;
begin
if SQLTimestamp = 0 then
begin
queryTime := SysUpTime;
dbTime := // SQL QUERY EXECUTION
queryTime := SysUpTime - queryTime;
LocalTimestamp := SysUpTime;
SQLTimestamp := dbTime + queryTime;
end;
Result := SQLTimestamp + (SysUpTime - LocalTimestamp);
end;
现在我的问题是:QueryPerformanceCounter和QueryPerformanceFrequency与GetTickCount有相同的限制吗?
The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days.