DosDateTimeToFileTime (kernel32)
Last changed: -82.47.136.24

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool DosDateTimeToFileTime(ushort wFatDate, ushort wFatTime,
   out UFILETIME lpFileTime);

User-Defined Types:

    public struct UFILETIME
    {
        public uint dwLowDateTime;
        public uint dwHighDateTime;
    }

Notes:

Sample and signature code originally used System.Runtime.InteropServices.FILETIME, but this uses ints instead of uints (DWORDs) meaning that this line:

    long hFT2 = (((long) ft.dwHighDateTime) << 32) + ft.dwLowDateTime;

gave incorrect results due to signs.

Tips & Tricks:

Please add some!

Sample Code:

    public struct UFILETIME
    {
        public uint dwLowDateTime;
        public uint dwHighDateTime;
    }

    private static DateTime ConvertDosDateTime(short DosDate, short DosTime)
    {
        UFILETIME filetime = new UFILETIME();
        DosDateTimeToFileTime(DosDate, DosTime, out filetime);
        //Reference: http://www.aspemporium.com/howto.aspx?hid=26
        long longfiletime = (long)(((ulong)filetime.dwHighDateTime << 32) +
            (ulong)filetime.dwLowDateTime);
        return DateTime.FromFileTimeUtc(longfiletime);
    }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation