转载:https://blog.csdn.net/flyyufenfei/article/details/79796035
#include<iostream> #include <ctime> using namespace std; int main() { struct tm t1 = { 0 }; struct tm t2 = { 0 }; double seconds; t1.tm_year = 2019 - 1900; t1.tm_mon = 6; t1.tm_mday = 6;//现在时间2019,7,6 t2.tm_year = 2020 - 1900; t2.tm_mon = 5; t2.tm_mday = 7;//明年高考时间2020,6,7 seconds = difftime(mktime(&t2), mktime(&t1));//转换结构体为time_t,利用difftime,计算时间差 cout << seconds / 86400 << endl;//最后输出时间,因为一天有86400秒(60*60*24) system("pause"); return 0; }