gpt4 book ai didi

windows - Windows FILETIME 结构是否包含闰秒?

转载 作者:可可西里 更新时间:2023-11-01 12:18:24 27 4
gpt4 key购买 nike

FILETIME structure根据 Microsoft 文档,从 1601 年 1 月 1 日(大概是那天的开始)开始计数,但这是否包括闰秒?

最佳答案

问题不应该是 FILETIME 是否包含闰秒。

应该是:

Do the people, functions, and libraries, who interpret a FILETIME (i.e. FileTimeToSystemTime) include leap seconds when counting the duration?

简单的回答是“不”FileTimeToSystemTime 将秒返回为 0..59


更简单的答案是:“当然不是,怎么可能呢?”。

我的 Windows 2000 机器不知道自发布以来的十年间增加了 2 个闰秒。它对 FILETIME 的任何解释都是错误的。


最后,不依赖于逻辑,我们可以通过直接的实验观察来确定发帖者问题的答案:

var
systemTime: TSystemTime;
fileTime: TFileTime;
begin
//Construct a system-time for the 12/31/2008 11:59:59 pm
ZeroMemory(@systemTime, SizeOf(systemTime));
systemtime.wYear := 2008;
systemTime.wMonth := 12;
systemTime.wDay := 31;
systemTime.wHour := 23;
systemtime.wMinute := 59;
systemtime.wSecond := 59;

//Convert it to a file time
SystemTimeToFileTime(systemTime, {var}fileTime);

//There was a leap second 12/31/2008 11:59:60 pm
//Add one second to our filetime to reach the leap second
filetime.dwLowDateTime := fileTime.dwLowDateTime+10000000; //10,000,000 * 100ns = 1s

//Convert the filetime, sitting on a leap second, to a displayable system time
FileTimeToSystemTime(fileTime, {var}systemTime);

//And now print the system time
ShowMessage(DateTimeToStr(SystemTimeToDateTime(systemTime)));

加一秒

12/31/2008 11:59:59pm

给予

1/1/2009 12:00:00am

而不是

1/1/2009 11:59:60pm

Q.E.D.

原发布者可能不喜欢它,但上帝故意操纵它,使一年不能被一天整除。他这样做只是为了搞砸程序员。

关于windows - Windows FILETIME 结构是否包含闰秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/130573/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com