mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2024-11-24 11:25:30 +00:00
35 lines
700 B
C
35 lines
700 B
C
#include <windows.h>
|
|
#include <wchar.h>
|
|
|
|
#define WINDOWS_TICKS_PER_SEC 10000000
|
|
#define EPOCH_DIFFERENCE 11644473600LL
|
|
|
|
long long WindowsTicksToUnixSeconds(long long);
|
|
|
|
int wmain(void) {
|
|
|
|
FILETIME ft = {0};
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
LARGE_INTEGER li = {0};
|
|
|
|
li.LowPart = ft.dwLowDateTime;
|
|
li.HighPart = ft.dwHighDateTime;
|
|
|
|
long long int hns = li.QuadPart;
|
|
|
|
wprintf(L"Windows API time: %lli\n", hns);
|
|
|
|
long long int utm = WindowsTicksToUnixSeconds(hns);
|
|
|
|
wprintf(L"Unix time: %lli\n", utm);
|
|
|
|
return 0;
|
|
}
|
|
|
|
long long int WindowsTicksToUnixSeconds(long long windowsTicks) {
|
|
|
|
return (windowsTicks / WINDOWS_TICKS_PER_SEC - EPOCH_DIFFERENCE);
|
|
}
|