tm_year 1900, ltm->tm_mon 1,。SCO UNIX下的时间问题。" />

SCO UNIX下的时间问题


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];
【SCO UNIX下的时间问题】 time(&cur_time);
ltm=localtime(&cur_time);
sprintf(firsttime, "dddddd",
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=%ldrn",firsttime,QSSJ_SC);

ltm=localtime(&QSSJ_SC);
sprintf(firsttime, "d-d-d d:d:d",
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=%ldrn",firsttime,QSSJ_SC);
运行结果为:
11111111 InTime=[20021215132903],qssj_sc=1035658399
22222222 InTime=[2002-10-27 02:53:19],qssj_sc=1035658399
为什么第二个时间是错的?

sprintf(tmp2,"20ldldldldldld",
(QSSJ_SC/60L/60L/24L/31L/12L 100L)0L,
QSSJ_SC/60L/60L/24L/31LL 1L,
QSSJ_SC/60L/60L/24L1L 1L,
QSSJ_SC/60L/60L$L,
QSSJ_SC/60L`L,
QSSJ_SC`L);
这样就解决问题了 。

    推荐阅读