Odpowiedź:
#include <ctime>
#include <iostream>
int main() {
struct std::tm a = {0, 0, 0, 24, 11, 121};
std::time_t x = std::mktime(&a);
std::time_t y = std::time(0);
if (x != (std::time_t)(-1) && y != (std::time_t)(-1)) {
int diff = std::difftime(x, y) / (60 * 60 * 24);
std::cout << std::ctime(&x);
std::cout << std::ctime(&y);
std::cout << "Pozostały = " << diff << " dni" << std::endl;
}
return 0;
}
Przykładowy wynik:
Fri Dec 24 00:00:00 2021
Sun Dec 19 19:43:07 2021
Pozostały = 4 dni