国际时间按时区索引号转换
生活随笔
收集整理的這篇文章主要介紹了
国际时间按时区索引号转换
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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月份還不足30gpsInfo.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--;}}}}}
總結
以上是生活随笔為你收集整理的国际时间按时区索引号转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Python】九十条简单py技巧打包(
- 下一篇: BZOJ3730 震波 【动态点分治】*