上程序: #include <cstdlib> #include <iostream> #include <time.h> #include <stdio.h> using namespace std; int main(int argc, char *argv[]) { time_t tNow =time(NULL); time_t tEnd = tNow + 1800; //注意下面两行的区别 struct tm* ptm = localtime(&tNow); struct tm* ptmEnd = localtime(&tEnd); char szTmp[50] = {0}; strftime(szTmp,50,"%H:%M:%S",ptm); char szEnd[50] = {0}; strftime(szEnd,50,"%H:%M:%S",ptmEnd); printf("%s /n",szTmp); printf("%s /n",szEnd); system("PAUSE"); return EXIT_SUCCESS; } 最后出来的结果是: 21:18:39 21:18:39 和最初想法不一致。 查阅localtime的文档,发现这段话: This