Skip to content

Commit

Permalink
Create unix_time.c
Browse files Browse the repository at this point in the history
  • Loading branch information
janbodnar committed Feb 1, 2016
1 parent 9b8e6c4 commit 0eaa39b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions datetime/unix_time.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#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);
}

0 comments on commit 0eaa39b

Please sign in to comment.