#include <cctype> #include <iostream> using namespace std; char* gettimestr(time_t itime, char* gettime, const char* format) { struct tm ptm; localtime_r(&itime, &ptm); strftime(gettime, 1024, format, &ptm); return gettime; } int main() { time_t tNow; tNow = time(NULL); int offset1 = 10; tNow = tNow - offset1 * 60; char cptimebegin[100]; char cptimeend[100]; gettimestr(tNow, cptimebegin, "%Y-%m-%d %H:%M:00"); printf("After offset1, the begin time is %s ", cptimebegin); int offset2 = 10; gettimestr(tNow - offset2 * 60, cptimeend, "%Y-%m-%d %H:%M:00"); printf("After offset2, the begin time is %s ", cptimeend); return 0; }