struct tm *ltm;
int QSSJ_y,QSSJ_m,QSSJ_d,QSSJ_h,QSSJ_f,QSSJ_s;
long cur_time,Intime,QSSJ_SC;
char firsttime[30],tmp2[255];
time(&cur_time);
ltm=localtime(&cur_time);
sprintf(firsttime, "%04d%02d%02d%02d%02d%02d",
ltm->tm_year+1900, \
ltm->tm_mon+1,\
ltm->tm_mday,\
ltm->tm_hour, \
ltm->tm_min, \
ltm->tm_sec);
QSSJ_y=ltm->tm_year+1900;
QSSJ_m=ltm->tm_mon+1;
QSSJ_d=ltm->tm_mday;
QSSJ_h=ltm->tm_hour;
QSSJ_f=ltm->tm_min;
QSSJ_s=ltm->tm_sec;
QSSJ_SC = (((((QSSJ_y-100)*12+QSSJ_m)*31+QSSJ_d-1)*24+QSSJ_h)*60+QSSJ_f)*6
printf("11111111 InTime=[%s],qssj_sc=%ld\r\n",firsttime,QSSJ_SC);
ltm=localtime(&QSSJ_SC);
sprintf(firsttime, "%04d-%02d-%02d %02d:%02d:%02d",
ltm->tm_year+1900, \
ltm->tm_mon+1,\
ltm->tm_mday,\
ltm->tm_hour, \
ltm->tm_min, \
ltm->tm_sec);
printf("22222222 InTime=[%s],qssj_sc=%ld\r\n",firsttime,QSSJ_SC);
运行结果为:
11111111 InTime=[20021215132903],qssj_sc=1035658399
22222222 InTime=[2002-10-27 02:53:19],qssj_sc=1035658399
为什么第二个时间是错的?