mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2024-11-24 11:25:30 +00:00
Update compare_time.c
This commit is contained in:
parent
90c9e5c132
commit
fdcff29388
@ -3,49 +3,45 @@
|
|||||||
|
|
||||||
int wmain(void) {
|
int wmain(void) {
|
||||||
|
|
||||||
SYSTEMTIME st1 = {0};
|
PDWORD cChars = NULL;
|
||||||
SYSTEMTIME st2 = {0};
|
HANDLE std = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
FILETIME ft1 = {0};
|
|
||||||
FILETIME ft2 = {0};
|
if (std == INVALID_HANDLE_VALUE) {
|
||||||
|
wprintf(L"Cannot retrieve standard output handle %d\n",
|
||||||
st1.wYear = 2015;
|
|
||||||
st1.wMonth = 4;
|
|
||||||
st1.wDay = 12;
|
|
||||||
|
|
||||||
st2.wYear = 2015;
|
|
||||||
st2.wMonth = 5;
|
|
||||||
st2.wDay = 12;
|
|
||||||
|
|
||||||
int r1 = SystemTimeToFileTime(&st1, &ft1);
|
|
||||||
|
|
||||||
if (r1 == 0) {
|
|
||||||
|
|
||||||
wprintf(L"Failed to convert system time to file time\n (%d)",
|
|
||||||
GetLastError());
|
GetLastError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r2 = SystemTimeToFileTime(&st2, &ft2);
|
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 (r2 == 0) {
|
if (r == 0) {
|
||||||
|
|
||||||
wprintf(L"Failed to convert system time to file time\n (%d)",
|
wprintf(L"GetDateFormatEx function failed %d\n",
|
||||||
GetLastError());
|
GetLastError());
|
||||||
|
|
||||||
|
CloseHandle(std);
|
||||||
|
|
||||||
return 1;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
short ct = CompareFileTime(&ft1, &ft2);
|
CloseHandle(std);
|
||||||
|
|
||||||
if (ct == -1) {
|
|
||||||
|
|
||||||
wprintf(L"4/12/2015 comes before 5/12/2015\n");
|
|
||||||
} else if (ct == 0) {
|
|
||||||
|
|
||||||
wprintf(L"4/12/2015 is equal to 5/12/2015\n");
|
|
||||||
} else if (ct == 1) {
|
|
||||||
|
|
||||||
wprintf(L"4/12/2015 comes after 5/12/2015\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user