您的位置:首页技术文章
文章详情页

SCO UNIX下的时间问题

【字号: 日期:2024-06-29 10:19:30浏览:57作者:猪猪

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

sprintf(tmp2,'20%02ld%02ld%02ld%02ld%02ld%02ld', (QSSJ_SC/60L/60L/24L/31L/12L+100L)%100L, QSSJ_SC/60L/60L/24L/31L%12L+1L, QSSJ_SC/60L/60L/24L%31L+1L, QSSJ_SC/60L/60L%24L, QSSJ_SC/60L%60L, QSSJ_SC%60L); 这样就解决问题了。
标签: Unix系统