-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdate_format.c
47 lines (31 loc) · 978 Bytes
/
date_format.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
}