1

我的程序以格式接收文件时间ulong,我必须将其转换为DateTime格式。所以这是我写的函数。

public static DateTime fileTimeToDateTime(ulong fileTime)
{
    long temp = (long)fileTime;
    DateTime dt1 = DateTime.FromFileTime(temp);
    return dt1;
}

但是对于文件时间2213360000,函数返回1/1/1601 12:00:00 AM但正确的应该是4/22/2009 3:28:29 PM所以然后我使用这个网页将文件时间转换为人类可读的时间,它给了我正确的值。所以我的功能看起来有问题。然后我使用此代码和平转换正确的日期。

string windowsTime = "4/22/2009 3:28:29 PM";
DateTime time = DateTime.Parse(windowsTime);
long ft = time.ToFileTime();

所以这里的输出ft128848589090000000而不是我得到的文件时间(2213360000)。所以看起来我的想法有问题。任何想法?

4

2 回答 2

2

FromFileTime期望 WindowsGetFileTime函数的输出——一个FILETIME结构。它测量自 1601 年 1 月 1 日 (UTC) 以来的 100 纳秒间隔数。

2213360000 100 纳秒的间隔约为 0.02 秒。

现在要看的是你从哪里得到你FILETIME的,或者你是否误解了这个方法的用途。您可以使用提供方法的代码来更新您的问题吗?

于 2014-08-10T04:34:11.250 回答
1

Did you consider the possibility that the converter from your link is broken? If you reduce the number by nine orders of magnitude, enter 2 instead of 2213360000 and let it convert, it still shows April 22, 2009, just few minutes less.

The number does not seem to be FILETIME. It could be unix stamp, seconds since 1970. In that case the date would be Feb 20, 2040, 6:13 AM. FYI in those units today's date is 1407649082.

于 2014-08-10T05:46:36.730 回答