65,186
社区成员




#include <stdio.h>
#include <time.h>
char a[]="19900101101010";
char b[]="20151118131023";
struct tm sta;
struct tm stb;
time_t ta;
time_t tb;
char tmpbuf[128];
int main() {
sscanf(a,"%4d%2d%2d%2d%2d%2d%2d",&sta.tm_year,&sta.tm_mon,&sta.tm_mday,&sta.tm_hour,&sta.tm_min,&sta.tm_sec);sta.tm_year-=1900;sta.tm_mon--;
sscanf(b,"%4d%2d%2d%2d%2d%2d%2d",&stb.tm_year,&stb.tm_mon,&stb.tm_mday,&stb.tm_hour,&stb.tm_min,&stb.tm_sec);stb.tm_year-=1900;stb.tm_mon--;
ta=mktime(&sta);
tb=mktime(&stb);
printf("From\n");
strftime(tmpbuf,128,"%Y-%m-%d %H:%M:%S",localtime(&ta));printf("%s\n",tmpbuf);
printf("to\n");
strftime(tmpbuf,128,"%Y-%m-%d %H:%M:%S",localtime(&tb));printf("%s\n",tmpbuf);
printf("elapse\n");
printf("%.15lg\n",difftime(tb,ta));
printf("second(s).\n");
return 0;
}
//From
//1990-01-01 10:10:10
//to
//2015-11-18 13:10:23
//elapse
//816663613
//second(s).
//