FILETIME Structure
The FILETIME
structure represents the number of 100‑nanosecond intervals since January 1, 1601 (UTC). It is used throughout the Windows API to specify timestamps.
Syntax
#include <windows.h>
typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME;
Members
Member | Description |
---|---|
dwLowDateTime | Low-order 32 bits of the file time. |
dwHighDateTime | High-order 32 bits of the file time. |
Remarks
- To convert a
FILETIME
to aULONGLONG
, combine the high and low parts:((ULONGLONG)ft.dwHighDateTime << 32) | ft.dwLowDateTime
. - Use
FileTimeToSystemTime
andSystemTimeToFileTime
for conversions toSYSTEMTIME
. - Many file‑related API functions return timestamps as
FILETIME
, e.g.,GetFileTime
,FindFirstFile
, etc.
Example (C++)
#include <windows.h>
#include <iostream>
int main() {
FILETIME ft;
// Get the current system time as FILETIME
GetSystemTimeAsFileTime(&ft);
// Convert to a readable format
SYSTEMTIME stUTC, stLocal;
FileTimeToSystemTime(&ft, &stUTC);
SystemTimeToTzSpecificLocalTime(nullptr, &stUTC, &stLocal);
std::cout << "Current local time: "
<< stLocal.wMonth << '/' << stLocal.wDay << '/' << stLocal.wYear << " "
<< stLocal.wHour << ':' << stLocal.wMinute << ':' << stLocal.wSecond << std::endl;
return 0;
}