mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2026-08-07 18:34:45 -04:00
Create date_format.c
This commit is contained in:
parent
a7356c7e76
commit
90c9e5c132
47
datetime/date_format.c
Normal file
47
datetime/date_format.c
Normal file
@ -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(<);
|
||||||
|
|
||||||
|
wchar_t buf[128] = {0};
|
||||||
|
|
||||||
|
int r = GetDateFormatEx(LOCALE_NAME_USER_DEFAULT, DATE_LONGDATE,
|
||||||
|
<, 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;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user