int main(void)
{
struct tm time_cha;
time_t t1,t2;
int d, year, month, day;
time_cha.tm_year = 1949 - 1900+32; //tm结构记录年为实际-1900,经过时间从1970年开始计算,不得小于1970年,考虑四年一闰,所以加32保证大于1970年
time_cha.tm_mon = 10 - 1;
time_cha.tm_mday = 1;
time_cha.tm_hour = 0;
time_cha.tm_min = 0;
time_cha.tm_sec = 1;
t1 = mktime(&time_cha);//获得从1970以来过去的时间,秒
printf("please input data: yyyy-m-d:");
scanf("%d-%d-%d",&year,&month,&day);
time_cha.tm_year = year - 1900+32;
time_cha.tm_mon = month - 1;
time_cha.tm_mday = day;
time_cha.tm_hour = 0;
time_cha.tm_min = 0;
time_cha.tm_sec = 1;
t2 = mktime(&time_cha);
d=(t2-t1)/(24*3600l);//经过的时间差(秒)/每天的秒数
printf("Pass time is %d days\n", d);
return 0;
} |