From 0eaa39b4716387312fd7c7c474c8b24692540d15 Mon Sep 17 00:00:00 2001 From: Jan Bodnar Date: Mon, 1 Feb 2016 10:04:06 +0100 Subject: [PATCH] Create unix_time.c --- datetime/unix_time.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 datetime/unix_time.c diff --git a/datetime/unix_time.c b/datetime/unix_time.c new file mode 100644 index 0000000..a576fed --- /dev/null +++ b/datetime/unix_time.c @@ -0,0 +1,34 @@ +#include +#include + +#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); +}