Background
UTC: Coordinated Universal Time.
GMT: Greenwich Mean Time.
FILETIME:
LOCALTIME:
SYSTEMTIME:
STRUCTURE/DEFINITION
For windows
SYSTEMTIME structure. The time is either in coordinated universal time (UTC) or local time, depending on the function that is being called.
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth; // based on 1(Jan)
WORD wDayOfWeek; // 0 for sunday, 1 for monday, … 6 for saturday
WORD wDay; // based on 1
WORD wHour; // from 0 to 23
WORD wMinute; // from 0 to 59
WORD wSecond; // from 0 to 59
WORD wMilliseconds; // from 0 to 999
} SYSTEMTIME;
FILETIME structure. This value represents the number of 100-nanosecond units since the beginning of January 1, 1601.
typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME, FAR *LPFILETIME;
ULARGE_INTEGER Union
typedef union _ULARGE_INTEGER {
struct {
DWORD LowPart;
DWORD HighPart;
};
struct {
DWORD LowPart;
DWORD HighPart;
} u;
ULONGLONG QuadPart;
} ULARGE_INTEGER,
*PULARGE_INTEGER;
Note: As the structure shown above.
FILETIME –> ULARGE_INTEGER: Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows. You should copy the low- and high-order parts of the file time to a ULARGE_INTEGER structure, perform 64-bit arithmetic on the QuadPart member.
ULARGE_INTEGER –> FILETIME: Cast pointer to ULARGE_INTEGER to FILETIME or copy the LowPart and HighPart members into the FILETIME structure.
time_t (__int64 or long integer)
struct tm {
int tm_sec; // from 0 to 59
int tm_min; // from 0 to 59
int tm_hour; // from 0 to 23
int tm_mday; // from 1 to 31
int tm_mon; // from 0 to 11
int tm_year; // Indicates the number of years since 1900.
int tm_wday; // 0 for sunday, 6 for saturday
int tm_yday; // from 0 to 365
int tm_isdst;
};
Retrieve Function
From total seconds (clocks) to tm structure for local time, lval is the variable for total seconds.
time_t t(lval);
struct tm * pltm = localtime((const time_t*)&t);
From total seconds (clocks) to tm structure for gmt time, lval is the variable for total seconds.
time_t t(lval);
struct tm * pgtm = gmtime((const time_t*)&t);
cout<<asctime((const tm*)pgtm);
From tm structure to calendar value
time_t _t = mktime(pltm);