输出日期下一天
1 #include <iostream> 2 #include <stdio.h> 3 #include <sstream> 4 5 using namespace std; 6 7 int main(int argc, char **argv) 8 { 9 int ret(0); 10 11 string line; 12 while (getline(cin, line)) 13 { 14 int year(0), month(0), day(0), hour(0), minute(0), second(0); 15 ret = sscanf(line.c_str(), "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &minute, &second); 16 if (6 != ret) 17 { 18 cout << "input date format invalid, please input like 2015-12-31 10:30:00" << endl; 19 continue; 20 } 21 22 struct tm curTm; 23 curTm.tm_year = year - 1900; 24 curTm.tm_mon = month -1; 25 curTm.tm_mday = day; 26 curTm.tm_hour = hour; 27 curTm.tm_min = minute; 28 curTm.tm_sec = second; 29 30 time_t curDaySec = mktime(&curTm); 31 time_t lastDaySec = curDaySec + (24 * 60 * 60); 32 33 struct tm * lastTm; 34 lastTm = localtime(&lastDaySec); 35 36 char result[100]; 37 strftime(result, sizeof(result), "%F %T", lastTm); 38 cout << "result: " << result << endl; 39 } 40 41 return 0; 42 }