我做了一个简单的程序来计算两天之间的天数:
#include <stdio.h>
#include <iostream>
#include <ctime>
#include <utility>
using namespace std;
int main(){
struct tm t1 = {0,0,0,28,2,104};
struct tm t2 = {0,0,0,1,3,104};
time_t x = mktime(&t1);
time_t y = mktime(&t2);
cout << difftime(y,x)/3600/24 << endl;
}
输出是 4 但是,我的预期结果是 1。我可以知道问题出在哪里吗?