Skip to content

Commit

Permalink
Create localtime_to_universaltime.c
Browse files Browse the repository at this point in the history
  • Loading branch information
janbodnar committed Feb 1, 2016
1 parent 200f998 commit e965a87
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions datetime/localtime_to_universaltime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <windows.h>
#include <wchar.h>

int wmain(void) {

SYSTEMTIME lt = {0};
GetLocalTime(&lt);

TIME_ZONE_INFORMATION tzi = {0};
GetTimeZoneInformation(&tzi);

SYSTEMTIME utm = {0};

int r = TzSpecificLocalTimeToSystemTime(&tzi, &lt, &utm);

if (r == 0) {

wprintf(L"Failed to convert local time to system time %d\n)",
GetLastError());
return 1;
}

wprintf(L"Date: %d/%d/%d\n", lt.wMonth, lt.wDay, lt.wYear);

wprintf(L"The local time is: %02d:%02d:%02d\n",
lt.wHour, lt.wMinute, lt.wSecond);

wprintf(L"The universal time is: %02d:%02d:%02d\n",
utm.wHour, utm.wMinute, utm.wSecond);

return 0;
}

0 comments on commit e965a87

Please sign in to comment.