2.1.8.7 DosDateTimeToFileTime


Description

The DosDateTimeToFileTime function converts MS-DOS date and time values to a 64-bit file time.

Syntax

BOOL DosDateTimeToFileTime( WORD wFatDate, WORD wFatTime, FILETIME * lpFileTime )

Parameters

wFatDate
[input]Specifies the MS-DOS date. The date is a packed 16-bit value with the following format.
Bits Contents
0-4 Day of the month (1-31)
5-8 Month (1 = January, 2 = February, and so on)
9-15 Year offset from 1980 (add 1980 to get actual year)
wFatTime
[input] Specifies the MS-DOS time. The time is a packed 16-bit value with the following format.
Bits Contents
0-4 Second divided by 2
5-10 Minute (0-59)
11-15 Hour (0-23 on a 24-hour clock)
lpFileTime
[output] Pointer to a FILETIME structure to receive the converted 64-bit file time.

Return

If the function succeeds, the return value is true; else return false.

Examples

EX1

int DosDateTimeToFileTime_Ex1()
{
	string  strFile = "c:\\myfile.txt";
    if(!strFile.IsFile())
    {
        HANDLE hFile = CreateFile(strFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hFile != INVALID_HANDLE_VALUE)
        {
            CloseHandle(hFile);
        }
    }
 
    WORD            FatDate;
    WORD            FatTime;
    FILETIME         localFiletime;    
    WIN32_FILE_ATTRIBUTE_DATA    fileInfo;    
 
    if(!GetFileAttributesEx(strFile, 0, &fileInfo))
    {
        return 0;
    }
 
    FileTimeToLocalFileTime(&fileInfo.ftLastWriteTime, &localFiletime);    
    FileTimeToDosDateTime(&localFiletime, &FatDate, &FatTime);
 
    int nYear = ((FatDate/512)& 255) +1980 ;    //9-15  bits
    int nMonth = (FatDate/32) & 15;                //5-8   bits
    int nDay = FatDate & 31;                    //0-4   bits
 
    FILETIME        FileTime;
    DosDateTimeToFileTime(FatDate, FatTime, &FileTime);    
    ASSERT(0 == CompareFileTime(&FileTime, &localFiletime) );
 
    FILETIME    ToFileTime;
    if( LocalFileTimeToFileTime(&fileInfo.ftLastAccessTime,&ToFileTime) )
    {
        ASSERT( 0 != ToFileTime.dwLowDateTime );
        ASSERT( 0 != ToFileTime.dwHighDateTime );
    }    
    return 1;

}

Remark

See Also

FileTimeToDosDateTime

Header to Include

origin.h

Reference