#include #include #include //for class system_clock #include //for the function localtime and structure tm using namespace std; /* p is a pointer to a structure of type tm. Because of the *const, p always points to the same structure. Because of the other const, we cannot use p to change the vales of the fields of the structure. Day of week is 0 for Sunday, 1 for Monday, etc. Day of year is 0 for Jan 1, 1 for Jan 2, etc. */ int main() { const auto now {chrono::system_clock::now()}; const time_t t {chrono::system_clock::to_time_t(now)}; const tm *const p {localtime(&t)}; cout << "t = " << t << "\n\n"; //Output the fields of the structure that p points to. cout << "The current year is " << p->tm_year + 1900 << ".\n"; cout << "The current month (1 to 12) is " << p->tm_mon + 1 << ".\n"; cout << "The current day (1 to 31) is " << p->tm_mday << ".\n\n"; cout << "This is day number " << p->tm_yday << " of the year.\n"; cout << "This is day number " << p->tm_wday << " of the week.\n\n"; cout << "The current hour (0 to 23) is " << p->tm_hour << ".\n"; cout << "The current minute (0 to 59) is " << p->tm_min << ".\n"; cout << "The current second (0 to 61) is " << p->tm_sec << ".\n\n"; if (p->tm_isdst >= 0) { cout << "Daylight Savings Time is "; if (p->tm_isdst == 0) { cout << "not "; } cout << "in effect.\n"; } return EXIT_SUCCESS; }