FileTimeToLocalFileTime

 

Description

Convert a file time to a local file time.

Syntax

BOOL FileTimeToLocalFileTime( const FILETIME * lpFileTime, FILETIME * lpLocalFileTime )

Parameters

lpFileTime
[input] pointer to file time to convert
lpLocalFileTime
[output] pointer to a FILETIME struct to receive the converted value

Return

TRUE if success, FALSE if error

Examples

EX1

int FileTimeToLocalFileTime_ex1()
{
    WIN32_FILE_ATTRIBUTE_DATA    fileInfo;
    string strFile = "c:\\test.txt";
    BOOL bRet = FALSE;
    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);
        }
    }

    if(GetFileAttributesEx(strFile, 0, &fileInfo))
    {
        FILETIME localFiletime;
        if(FileTimeToLocalFileTime(&fileInfo.ftLastWriteTime, &localFiletime))
        {
            SYSTEMTIME sysTime;
            if(FileTimeToSystemTime(&localFiletime, &sysTime))
            {
                printf("%s is last modified at %.2d-%.2d-%4d %.2d:%.2d:%.2d\n",
                strFile,
                sysTime.wMonth,sysTime.wDay,sysTime.wYear,
                sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
                return 1;
            }
        }
    }
    return 0;
}

Remark

The FileTimeToLocalFileTime function converts a file time to a local file time. This function uses the current settings for the time zone and daylight saving time. Therefore, if it is daylight saving time, this function will take daylight saving time into account, even if the time you are converting is in standard time.

See Also

LocalFileTimeToFileTime

header to Include

origin.h

Reference