代码直接上了,当gm时间转本地时间时,在windows下面没有timegm函数,但是可以通过mktime函数减去timezone变量(timezone是C runtime libary的全局变量)来获取
bool LocalTimeToUTC(MY_TIME_T *pTime)
{
struct tm newtime;
newtime.tm_year = pTime->u16Year - 1900;
newtime.tm_mon = pTime->u8Month - 1;
newtime.tm_mday = pTime->u8Day;
newtime.tm_hour = pTime->u8Hour;
newtime.tm_min = pTime->u8Minute;
newtime.tm_sec = pTime->u8Second;
newtime.tm_wday = 0;
newtime.tm_yday =0;
newtime.tm_isdst = 0;
time_t time = mktime(&newtime);
struct tm *pnewtime;
pnewtime = gmtime(&time);
if(pnewtime != NULL)
{
pTime->u16Year = pnewtime->tm_year + 1900;
pTime->u8Month = pnewtime->tm_mon + 1;
pTime->u8Day = pnewtime->tm_mday;
pTime->u8Hour = pnewtime->tm_hour;
pTime->u8Minute = pnewtime->tm_min;
pTime->u8Second = pnewtime->tm_sec;
}
return true;
}
bool UTC