filetimetosystemtime (kernel32)
Last changed: omniware@gmail.com-209.63.205.126

.
Summary

C# Signature:

[DllImport("kernel32.dll",
        CallingConvention=CallingConvention.Winapi,
        SetLastError=true)]
static extern bool FileTimeToSystemTime([In] ref FILETIME lpFileTime,
   out SYSTEMTIME lpSystemTime);

VB.Net Signature

<DllImport( _
       "kernel32.dll", _
       CharSet:=CharSet.Auto, _
       SetLastError:=True)> _
   Friend Shared Function FileTimeToSystemTime( _
                        <[In]()> ByRef lpFileTime As FILETIME, _
                        <Out()> ByRef lpSystemTime As SYSTEMTIME) _
               As Boolean
   End Function

User-Defined Types:

FileTime and SystemTime.

Notes:

By setting the SetLastError property to true, a System.ComponentModel.Win32Exception will generated if the function fails.

Tips & Tricks:

For .NET Compact Framework:

this function is contained in "coredll.dll" not "kernel32.dll"

Sample Code:

If you are trying to parse the Modified (e.g. B0D37BF53EBEC501B5) value in the URL (Shortcut) file you could use the following code:

References used for the code below:

http://www.fmtz.com/formats/url-file-format/article

FileTime page

C#

    public static DateTime FileTimeToSystemTime(string hexTS) {
        string lowDT = string.Format("{0}{1}{2}{3}",
            hexTS.Substring(6, 2), hexTS.Substring(4, 2), hexTS.Substring(2, 2), hexTS.Substring(0, 2));

        string highDT = string.Format("{0}{1}{2}{3}",
            hexTS.Substring(14, 2), hexTS.Substring(12, 2), hexTS.Substring(10, 2), hexTS.Substring(8, 2));

        FILETIME fileTime;
        fileTime.dwHighDateTime = int.Parse(highDT, System.Globalization.NumberStyles.HexNumber);
        fileTime.dwLowDateTime = int.Parse(lowDT, System.Globalization.NumberStyles.HexNumber);
        long hFT2 = (((long)fileTime.dwHighDateTime) << 32) | ((uint)fileTime.dwLowDateTime);
        return DateTime.FromFileTimeUtc(hFT2);
    }

Alternative Managed API:

You really do not need to use this function as you could use the FromFileTime or FromFileTimeUtc on DateTime class. Refer to the sample code provided in the FileTime page.

Documentation