typedef struct{
int year;
int month;
int day;
int hour;
int minute;
int second;
int millisecond;
}DATE_TIME;
typedef struct{
DATE_TIME D; //时间
char status; //接收状态
double latitude; //纬度
double longitude; //经度
char NS; //南北纬
char EW; //东西经
double speed; //速度
double high; //高度
}GPS_INFO;
typedef struct{
BYTE ucTimeZone; //时区编号
INT addOrSub; //时间加减
INT hour; //时
INT minute; //分
}T_TimeZoneOffset; /*时区对应偏移量*/
T_TimeZoneOffset gTimeZoneOffsetTable[] =
{
{0 ,-1,12,00},
{2 ,-1,11,00},
{4 ,-1,10,00},
{6 ,-1,9 ,00},
{8 ,-1,8 ,00},
{10,-1,7 ,00},
{12,-1,6 ,00},
{14,-1,5 ,00},
{15,-1,4 ,30},
{16,-1,4 ,00},
{17,-1,3 ,30},
{18,-1,3 ,00},
{20,-1,2 ,00},
{22,-1,1 ,00},
{24, 0,0 ,00},
{26,+1,1 ,00},
{28,+1,2 ,00},
{30,+1,3 ,00},
{31,+1,3 ,30},
{32,+1,4 ,00},
{33,+1,4 ,30},
{34,+1,5 ,00},
{35,+1,5 ,30},
{51,+1,5 ,45},
{36,+1,6 ,00},
{37,+1,6 ,30},
{38,+1,7 ,00},
{40,+1,8 ,00},
{42,+1,9 ,00},
{43,+1,9 ,30},
{44,+1,10,00},
{46,+1,11,00},
{48,+1,12,00},
{50,+1,13,00},
};
VOID BspConvertTimeToLocal(BYTE ucTimeZoneIndex, DATE_TIME *GPS)
{
WORD32 dwLoop;
INT sPn = 0;
INT hour = 0;
INT minute = 0;
/*时区查找*/
for(dwLoop=0; dwLoop<sizeof(gTimeZoneOffsetTable)/sizeof(T_TimeZoneOffset); dwLoop++)
{
if(ucTimeZoneIndex == gTimeZoneOffsetTable[dwLoop].ucTimeZone)
{
sPn = gTimeZoneOffsetTable[dwLoop].addOrSub;
hour = gTimeZoneOffsetTable[dwLoop].hour;
minute = gTimeZoneOffsetTable[dwLoop].minute;
break;
}
}
if(sPn >= 0) //东部时区
{
/*分处理*/
gpsInfo.D.minute = gpsInfo.D.minute + minute;
if(gpsInfo.D.minute>59){
gpsInfo.D.minute -= 60;
gpsInfo.D.hour++;
}
/*时处理*/
gpsInfo.D.hour = gpsInfo.D.hour + hour;
if(gpsInfo.D.hour>23)
{
gpsInfo.D.hour-=24;
gpsInfo.D.day+=1;
if(gpsInfo.D.month==2 ||gpsInfo.D.month==4 ||gpsInfo.D.month==6 ||gpsInfo.D.month==9 ||gpsInfo.D.month==11 ){
if(gpsInfo.D.day>30){ //上述几个月份是30天每月,2月份还不足30
gpsInfo.D.day=1;
gpsInfo.D.month++;
}
}
else{
if(gpsInfo.D.day>31){ //剩下的几个月份都是31天每月
gpsInfo.D.day=1;
gpsInfo.D.month++;
}
}
if(gpsInfo.D.year % 4 == 0 ){//
if(gpsInfo.D.day > 29 && gpsInfo.D.month ==2){ //闰年的二月是29天
gpsInfo.D.day=1;
gpsInfo.D.month++;
}
}
else{
if(gpsInfo.D.day>28 &&gpsInfo.D.month ==2){ //其他的二月是28天每月
gpsInfo.D.day=1;
gpsInfo.D.month++;
}
}
if(gpsInfo.D.month>12){
gpsInfo.D.month-=12;
gpsInfo.D.year++;
}
}
}
else //西部时区
{
/*分处理*/
gpsInfo.D.minute = gpsInfo.D.minute - minute;
if(gpsInfo.D.minute<0){
gpsInfo.D.minute += 60;
gpsInfo.D.hour--;
}
/*时处理*/
gpsInfo.D.hour = gpsInfo.D.hour - hour;
if(gpsInfo.D.hour<0)
{
gpsInfo.D.hour+=24;
gpsInfo.D.day--;
if(gpsInfo.D.day <= 0)
{
gpsInfo.D.month--;
if (gpsInfo.D.month==1 ||gpsInfo.D.month==3 ||gpsInfo.D.month==5 ||gpsInfo.D.month==7 ||gpsInfo.D.month==8||gpsInfo.D.month==10)
{
gpsInfo.D.day = 31;
}
else if (gpsInfo.D.month==4 ||gpsInfo.D.month==6 ||gpsInfo.D.month==9 ||gpsInfo.D.month==11)
{
gpsInfo.D.day = 30;
}
else if (gpsInfo.D.month==2)
{
if(gpsInfo.D.year % 4 == 0 ) //闰年的二月是29天
{
gpsInfo.D.day = 29;
}
else //其他的二月是28天每月
{
gpsInfo.D.day = 28;
}
}
else /*month=0,year--,month=12*/
{
gpsInfo.D.day = 31;
gpsInfo.D.month = 12;
gpsInfo.D.year--;
}
}
}
}
}
国际时间按时区索引号转换
于 2023-03-14 16:24:42 首次发布