// get_time example #include // cin, cout #include // get_time #include // struct tm #include #include #include using namespace std; int main() { struct tm when; const string monthName[] = { "January","February","March","April","May","June", "July","August","September","October","November","December" }; cout << "Please, enter the time (hh:mn): "; cin >> get_time(&when, "%R"); // extract time (24H format) if (cin.fail()) cout << "Error reading time\n"; else { cout << "The time entered is: "; cout << when.tm_hour << " hours and " << when.tm_min << " minutes\n"; } cout << "Please, enter the date (mm/dd/yy): "; cin >> get_time(&when, "%D"); // extract date if (cin.fail()) cout << "Error reading date\n"; else { cout << "The date entered is: "; cout << monthName[when.tm_mon] << " " << when.tm_mday << ", "; cout << when.tm_year + 1900 << endl; } tm t = {}; istringstream ss("2011-February-18 23:12:34"); cout.imbue(locale("")); ss >> get_time(&t, "%Y-%b-%d %H:%M:%S"); if (ss.fail()) { cout << "Parse failed" << endl; } else { cout << put_time(&t, "%c") << endl; cout << put_time(&t, "%D %r") << endl; } }