计算两日期之间天数的C语言程序

求解!万分感谢
2024-12-19 22:55:07
推荐回答(1个)
回答1:

#include
#include
#include

int main(void)
{
time_t t1;
time_t t2;

struct tm OldTime;
struct tm NewTime;

memset(&OldTime,0x0,sizeof(tm));
OldTime.tm_year = 110;// 2010 年表示为 2010 - 1900 = 110
OldTime.tm_mon = 12;
OldTime.tm_mday = 6;

memset(&NewTime,0x0,sizeof(tm));
NewTime.tm_year = 111;// 2011 年表示为 2011 - 1900 = 111
NewTime.tm_mon = 12;
NewTime.tm_mday = 6;

t1 = mktime(&NewTime); //2011-12-6
t2 = mktime(&OldTime); //2010-12-6

printf("%d",(t1-t2)/(24*3600));

return 0;
}