Skip to content

Commit

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

int wmain(void) {

PDWORD cChars = NULL;
HANDLE std = GetStdHandle(STD_OUTPUT_HANDLE);

if (std == INVALID_HANDLE_VALUE) {
wprintf(L"Cannot retrieve standard output handle %d\n",
GetLastError());
return 1;
}

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

wchar_t buf[128] = {0};

int r = GetDateFormatEx(LOCALE_NAME_USER_DEFAULT, DATE_LONGDATE,
&lt, NULL, buf, sizeof(buf)/sizeof(buf[0]), NULL);

if (r == 0) {

wprintf(L"GetDateFormatEx function failed %d\n",
GetLastError());

CloseHandle(std);

return 1;
}

WriteConsoleW(std, buf, wcslen(buf), cChars, NULL);

r = CloseHandle(std);

if (r == 0) {

wprintf(L"Cannot close console handle %d\n",
GetLastError());
return 1;
}

CloseHandle(std);

return 0;
}

0 comments on commit 90c9e5c

Please sign in to comment.