2.1.8.24 LocalFileTimeToFileTime


Description

The LocalFileTimeToFileTime function converts a local file time to a file time based on the Coordinated Universal Time (UTC).

Syntax

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

Parameters

lpLocalFileTime
[input]Pointer to a FILETIME structure to receive the converted UTC-based file time. This parameter cannot be the same as the lpLocalFileTime parameter.
lpFileTime
[output] Pointer to a FILETIME structure that specifies the local file time to be converted into a UTC-based file time.

Return

TRUE if success, FALSE if error

Examples

EX1

int LocalFileTimeToFileTime_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(LocalFileTimeToFileTime(&fileInfo.ftLastWriteTime, &localFiletime))
        {
            SYSTEMTIME sysTime;
            if(FileTimeToSystemTime(&localFiletime, &sysTime))
            {
                printf("Based on UTC time,%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

See Also

FileTimeToLocalFileTime

Header to Include

origin.h

Reference