1

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?

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147
  • 1
    Just a guess, but it probably just has less precision than a full file time. Multiplying by some power of 10 will likely yield the "correct" results. Though it would be best if you could verify from the source what exactly is meant by the value you receive. – Matt Johnson-Pint Aug 10 '14 at 20:23

2 Answers2

2

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?

Cory Nelson
  • 29,236
  • 5
  • 72
  • 110
  • This file time is getting form a DLL given by a different company. but you see the web page giving me the correct datetime. So there shod be a way to get it. – Nayana Adassuriya Aug 10 '14 at 04:48
  • 2
    You'll need to see what format that website is reading it as. It is definitely _not_ a `FILETIME` for 2009. – Cory Nelson Aug 10 '14 at 04:57
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.

MirekE
  • 11,515
  • 5
  • 35
  • 28