本文介绍了Windows FILETIME结构是否包含leap秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FILETIME结构很重要根据Microsoft文档的说明,从1601年1月1日(大概是当天开始)开始,但这是否包括leap秒?

The FILETIME structure counts from January 1 1601 (presumably the start of that day) according to the Microsoft documentation, but does this include leap seconds?

推荐答案

问题不应该在于FILETIME是否包含The秒.

The question shouldn't be if FILETIME includes leap seconds.

应该是:

简单的回答是否" . FileTimeToSystemTime将秒返回为0..59.

The simple answer is "no". FileTimeToSystemTime returns seconds as 0..59.

简单的答案是:"当然不是,怎么可能?".

The simpler answer is: "of course not, how could it?".

我的Windows 2000计算机不知道自发布以来的十年间增加了2个leap秒.它对FILETIME所做的任何解释都是错误的.

My Windows 2000 machine doesn't know that there were 2 leap seconds added in the decade since it was released. Any interpretation it makes of a FILETIME is wrong.

最后,我们可以通过直接的实验观察来确定张贴者问题的答案,而不是依靠逻辑:

Finally, rather than relying on logic, we can determine by direct experimental observation, the answer to the posters question:

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.

原始海报可能不喜欢它,但上帝故意将其操纵,以使一年不能被一天整除.他这样做只是为了弄糟程序员.

Original poster might not like it, but god intentionally rigged it so that a year is not evenly divisible by a day. He did it just to screw up programmers.

这篇关于Windows FILETIME结构是否包含leap秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 09:49