FileTimeToLocalFileTime

Description

Converts a FILETIME structure, which represents coordinated universal time (UTC), to a local date and time.

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

Parameters

  • lpFileTime

    [in]
    A pointer to a FILETIME structure that contains the time to convert.

  • lpLocalFileTime

    [out]
    A pointer to a FILETIME structure that receives the local date and time.

Return Value

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

  • A FILETIME structure contains a 64-bit value that represents the number of 100-nanosecond intervals since January 1, 1601 (UTC).
  • The system uses a 64-bit value to represent time. This value is the number of 100-nanosecond intervals since 12:00 A.M. January 1, 1601 (Annum Domini), coordinated universal time (UTC). A FILETIME structure should not be treated as a date and time string.
  • To convert a FILETIME to a more usable format, use the FileTimeToSystemTime or FileTimeToDosDateTime functions.
  • The conversion performed by this function uses the system's current time zone information.

Requirements

  • Minimum supported client

    Windows 2000 Professional [desktop apps only]

  • Minimum supported server

    Windows 2000 Server [desktop apps only]

  • Header

    FileAPI.h (include Windows.h)

  • Library

    Use Kernel32.lib

  • DLL

    Kernel32.dll

Example

For a sample code snippet, see Getting the Last-Modified Time.


#include <windows.h>
#include <iostream>

int main() {
    FILETIME ft_utc;
    FILETIME ft_local;

    // Get current UTC time
    GetSystemTimeAsFileTime(&ft_utc);

    // Convert UTC to local time
    if (FileTimeToLocalFileTime(&ft_utc, &ft_local)) {
        SYSTEMTIME st_local;
        // Convert FILETIME to SYSTEMTIME for easier display
        if (FileTimeToSystemTime(&ft_local, &st_local)) {
            std::wcout << L"UTC Time: " << ft_utc.dwHighDateTime << L" " << ft_utc.dwLowDateTime << std::endl;
            std::wcout << L"Local Time: "
                       << st_local.wYear << L"/" << st_local.wMonth << L"/" << st_local.wDay << L" "
                       << st_local.wHour << L":" << st_local.wMinute << L":" << st_local.wSecond << std::endl;
        } else {
            std::wcerr << L"FileTimeToSystemTime failed. Error: " << GetLastError() << std::endl;
        }
    } else {
        std::wcerr << L"FileTimeToLocalFileTime failed. Error: " << GetLastError() << std::endl;
    }

    return 0;
}