C语言中如何计算时间差
如何将两个包含“年月日时分”的5个字节数据进行比较,最后得出一个时间间隔(总分钟数)?其中的年份用后两位表示,如2010年8月31日9时26分表示为:1008310926...
如何将两个包含“年月日时分”的5个字节数据进行比较,最后得出一个时间间隔(总分钟数)?
其中的年份用后两位表示,如2010年8月31日9时26分表示为:1008310926
最后输出必须是时间差(总的分钟)
补充:在KEIL C中编译没有time.h这个头文件调用怎么办? 展开
其中的年份用后两位表示,如2010年8月31日9时26分表示为:1008310926
最后输出必须是时间差(总的分钟)
补充:在KEIL C中编译没有time.h这个头文件调用怎么办? 展开
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
unsigned char time1[] = { 10, 8, 31, 9, 26 };
unsigned char time2[] = { 10, 8, 31, 9, 50 };
struct tm t1 = {0};
struct tm t2 = {0};
time_t _t1;
time_t _t2;
double diff;
t1.tm_year = time1[0] + 100;
t1.tm_mon = time1[1];
t1.tm_mday = time1[2];
t1.tm_hour = time1[3];
t1.tm_min = time1[4];
t2.tm_year = time2[0] + 100;
t2.tm_mon = time2[1];
t2.tm_mday = time2[2];
t2.tm_hour = time2[3];
t2.tm_min = time2[4];
_t1 = _mkgmtime( &t1 );
_t2 = _mkgmtime( &t2 );
diff = difftime(_t2, _t1 );
printf( "相差 %.0f 分钟\n", diff / 60 );
}
#include <stdlib.h>
#include <time.h>
void main()
{
unsigned char time1[] = { 10, 8, 31, 9, 26 };
unsigned char time2[] = { 10, 8, 31, 9, 50 };
struct tm t1 = {0};
struct tm t2 = {0};
time_t _t1;
time_t _t2;
double diff;
t1.tm_year = time1[0] + 100;
t1.tm_mon = time1[1];
t1.tm_mday = time1[2];
t1.tm_hour = time1[3];
t1.tm_min = time1[4];
t2.tm_year = time2[0] + 100;
t2.tm_mon = time2[1];
t2.tm_mday = time2[2];
t2.tm_hour = time2[3];
t2.tm_min = time2[4];
_t1 = _mkgmtime( &t1 );
_t2 = _mkgmtime( &t2 );
diff = difftime(_t2, _t1 );
printf( "相差 %.0f 分钟\n", diff / 60 );
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询