两个日期相减,怎么能得到天数和小时数

来源:百度知道 编辑:UC知道 时间:2024/05/12 03:20:32
比如A1为2009-11-1 11:00,B2为2009-11-3 16:40,我想的B1-A1的差值显示为 天数和小时数(如 2 5:40)
请高手帮忙

根据你的要求 我只写了一个月中的情况,你别超出一个月就行!
#include<stdio.h>
#define H 60
#define D 24
int fun(int d,int h,int m );/* find the all minute*/
void fun1(int min1,int min2);/*find the answer*/
void main()
{

int year,month,day1,hour1,min1,day2,hour2,min2;
int min3,min4;
printf("input the first date(like 2009 11 1 11:30):");
while(scanf("%d %d %d %d:%d",&year,&month,&day1,&hour1,&min1))
{
printf("input the second date(like 2009 11 2 11:30):");
scanf("%d %d %d %d:%d",&year,&month,&day2,&hour2,&min2);
min3=fun(day1,hour1,min1);
min4=fun(day2,hour2,min2);
fun1(min3,min4);
printf("input again or input q to leave!\n");
printf("input the first date(like 2009 11 1 11:30):");
}

}
void fun1(int min1,int min2)
{
int min=(min2-min1)%H;/*find the minute*/
int hour1=(min2-min1)/H;/*find the first