Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

DosDateTimeToFileTime (kernel32)
 
.
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!

Alternate C# process:

    [DllImport("kernel32", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    private static extern int DosDateTimeToFileTime(ushort dateValue, ushort timeValue, out UInt64 fileTime);

    [DllImport("kernel32", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    private static extern int FileTimeToDosDateTime(ref UInt64 fileTimeInfo, out ushort dateValue, out ushort TimeValue);

    void Test()
    {
        UInt64 data = Convert.ToUInt64(DateTime.Now.ToFileTime());

        int result = 0;
        ushort dateValue = 0;
        ushort timeValue = 0;

        result = FileTimeToDosDateTime(ref data, out dateValue, out timeValue);
        data = 0;
        result = DosDateTimeToFileTime(dateValue, timeValue, out data);

       Console.Write(DateTime.FromFileTime(Convert.ToInt64(data)).ToString("MM/dd/yyyy hh:mm:ss tt"));
    }

Sample Code:

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

    private static DateTime ConvertDosDateTime(ushort DosDate, ushort DosTime)
    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

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions