简单类型 / 日期和时间

#include <iostream>
using namespace std;

void showDate(string name, time_t date) {
    char shortStyle[20];
    strftime(shortStyle, sizeof(shortStyle),
        "%Y-%m-%d"localtime(&date));

    cout << name << ": " << shortStyle << endl;
}

time_t now = time(0);
time_t yesterday = now - (24 * 60 * 60);
time_t tomorrow = now + 86400;

tm tm = *localtime(&now);
tm.tm_mon += 1;
time_t nextMonth = mktime(&tm);

tm = *localtime(&now);
tm.tm_year += 1;
time_t nextYear = mktime(&tm);

showDate("now", now);
showDate("yesterday", yesterday);
showDate("tomorrow", tomorrow);
showDate("nextMonth", nextMonth);
showDate("nextYear", nextYear);