unsigned int xDate2Seconds(_xtime *time){ static unsigned int month[12]={ /*01月*/xDAY*(0), /*02月*/xDAY*(31), /*03月*/xDAY*(31+28), /*04月*/xDAY*(31+28+31), /*05月*/xDAY*(31+28+31+30), /*06月*/xDAY*(31+28+31+30+31), /*07月*/xDAY*(31+28+31+30+31+30), /*08月*/xDAY*(31+28+31+30+31+30+31), /*09月*/xDAY*(31+28+31+30+31+30+31+31), /*10月*/xDAY*(31+28+31+30+31+30+31+31+30), /*11月*/xDAY*(31+28+31+30+31+30+31+31+30+31), /*12月*/xDAY*(31+28+31+30+31+30+31+31+30+31+30) }; unsigned int seconds = 0; unsigned int year = 0; year = time->year-1970; //不考虑2100年千年虫问题 seconds = xYEAR*year + xDAY*((year+1)/4); //前几年过去的秒数 seconds += month[time->month-1]; //加上今年本月过去的秒数 if( (time->month > 2) && (((year+2)%4)==0) )//2008年为闰年 seconds += xDAY; //闰年加1天秒数 seconds += xDAY*(time->day-1); //加上本天过去的秒数 seconds += xHOUR*time->hour; //加上本小时过去的秒数 seconds += xMINUTE*time->minute; //加上本分钟过去的秒数 seconds += time->second; //加上当前秒数
seconds -= 8 * xHOUR; return seconds;}
将UNIX时间转为UTC+8 即北京时间
取消
评论