|
就是我取了unix时间戳,因为要符合北京时间, 所以表达式是 unixtime = unixtime - (16*3600); 这样计算出来时间对应不上,但是如果是unixtime = unixtime -57600; 就对应上了,完整函数如下,- idata u16 nian,yue,ri,shi,fen,miao;
- void newjudge(u32 unixtime)
- {
- u16 year,month,day,hour,minute,second;
-
- u16 leap;
- u16 days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
- //unixtime=unixtime+28800;
- //unixtime=unixtime-57600; //(-24+8) hour ok
- unixtime=unixtime-(16*3600); //error
-
- second=unixtime % 60;
- unixtime=unixtime / 60;
- minute=unixtime % 60;
- unixtime=unixtime / 60;
- hour=unixtime % 24;
- unixtime=unixtime / 24;
- year=1970;
- leap=0;
- while (unixtime>=365)
- {
- if (leap==0)
- {
- if ((year % 4==0) && (year % 100!=0))
- {
- if (unixtime>=366)
- {
- unixtime=unixtime-366;
- year++;
- }
- else
- break;
- }
- else
- {
- unixtime=unixtime-365;
- year++;
- }
- }
- else
- {
- if (unixtime>=366)
- {
- unixtime=unixtime-366;
- year++;
- }
- else
- break;
- }
- if ((year % 4==0) && (year % 100!=0))
- leap=1;
- else
- leap=0;
- }
- if (leap==1)
- days[1]=29;
- month=1;
- while (unixtime>=days[month-1])
- {
- unixtime=unixtime-days[month-1];
- month++;
- }
- day=unixtime+1;
- miao=second;
- fen=minute;
- shi=hour;
- ri=day;
- yue=month;
- nian=year;
- }
复制代码
麻烦大神们指点下
|
|