#include #include #include #include //for time_t, time, tm, localtime using namespace std; int main() { const time_t t = time(0); if (t == -1) { cerr << "time failed\n"; return EXIT_FAILURE; } //p is a pointer to a structure const tm *p = localtime(&t); if (p == 0) { cerr << "localtime failed\n"; return EXIT_FAILURE; } const int year = p->tm_year + 1900; const int month = p->tm_mon + 1; const int day = p->tm_mday; const int hour = p->tm_hour; const int minute = p->tm_min; const int second = p->tm_sec; cout << month << "/" << day << "/" << year << "\n" << hour << ":" << setfill('0') << setw(2) << minute << ":" << setw(2) << second << "\n"; return EXIT_SUCCESS; }