简体   繁体   中英

Convert ulong FILETIME to datetime

My program receiving file time in ulong format and I have to convert it to DateTime format. So here is the function I wrote.

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

But for the filetime 2213360000 ,function returns 1/1/1601 12:00:00 AM but the correct should be 4/22/2009 3:28:29 PM So then I used this webpage to convert filetime to human readable time and it gives me the correct value. So it looks something wrong with my function. Then I convert the correct date using this code peace.

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

So here output ft is 128848589090000000 and it not the filetime that I got ( 2213360000 ). So looks something wrong with the way I think. Any idea?

FromFileTime expects output from Windows' GetFileTime function -- a FILETIME struct. It measures the number of 100-nanosecond intervals since January 1, 1601 (UTC).

2213360000 100-nanosecond intervals is about 0.02 seconds.

The thing to look at now is where you're getting your FILETIME from, or if you misunderstood what the method is made for. Can you update your question with the code feeding your method?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM