求教:在C中的日期问题
有什么方法可以算出两天之间的天数??如1972。5。1到2005。12。1
谢谢~~~~
#include <stdio.h> #include <time.h> int main() { struct tm t1, t2; double day_number = 0; time_t t_of_t1, t_of_t2; t1.tm_year = 1972 - 1900; t2.tm_year = 2005 - 1900; t1.tm_mon = 4; // 5 月 t2.tm_mon = 11; // 11 月 t1.tm_mday = 1; t2.tm_mday = 1; t1.tm_hour = t2.tm_hour = 0; t1.tm_min = t2.tm_min = 0; t1.tm_sec = t2.tm_sec = 1; t1.tm_isdst = t2.tm_isdst = 0; t_of_t1 = mktime(&t1); t_of_t2 = mktime(&t2); day_number = difftime(t_of_t2, t_of_t1); printf("Days from 05-1-1972 To 12-1-2005 is:%d\n",(int)(day_number/(24*3600))); return 0;
} output: Days from 05-1-1972 To 12-1-2005 is:12267 Press any key to continue...