#include
#include <time.h>
#include <stdio.h>
using namespace std;
time_t convert(int year, int mon, int day, int hour, int min, int sec, int week)
{
tm info;
info.tm_year = year-1900;
info.tm_mon = mon-1;;
info.tm_mday = day;
info.tm_hour = hour;
info.tm_min = min;
info.tm_sec = sec;
info.tm_wday = week;
return mktime(&info); // mktime()函数可以将tm结构体转化成秒值也就是time_t类型
}
int main()
{
int s_year, s_mon, s_day;
cout << “请输入开始的日期(xxxx xx xx):” ;
cin >> s_year >> s_mon >> s_day ;
time_t start = convert(s_year, s_mon, s_day, 0, 0, 0, 0);
cout << “请输入结束的日期(xxxx xx xx):” ;
int e_year , e_mon, e_day;
cin >> e_year >> e_mon >> e_day;
time_t end = convert(e_year, e_mon, e_day, 0, 0, 0, 0);
int diff = (int) (end - start);
int days = diff/(606024);
cout << “中间相差了” << days << “天。” << endl;
system("pause");
return 0;
}