【发布时间】:2015-02-19 17:27:29
【问题描述】:
我有 2 个时间字符串,想找出它们之间的区别。我的代码有效。但是当我尝试相同的值时,它会显示不同的输出。这是我的代码:
#include <time.h>
#include <stdio.h>
time_t convtotime(char *time_detail,char *format){
struct tm tm;
strptime(time_detail,format,&tm);
time_t t = mktime(&tm);
return t;
}
int main(int argc, char const *argv[])
{
char buff[25];
time_t newtime = convtotime("12/Dec/2014:10:44:19","%d/%b/%Y:%H:%M:%S");
time_t oldtime = convtotime("12/Dec/2014:10:44:35","%d/%b/%Y:%H:%M:%S");
printf("%lf",difftime(oldtime,newtime));
}
它输出:
3616.000000
或
16.000000
【问题讨论】:
-
你的意思是当你再次运行这个确切的程序时得到不同的结果?