!979 fix: mktime获取的时间缺少时区信息

Merge pull request !979 from Zhaotianyu/20221228mktime_fix
This commit is contained in:
openharmony_ci 2022-12-29 10:21:38 +00:00 committed by Gitee
commit 6633aabf89
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 2 additions and 2 deletions

View File

@ -664,7 +664,7 @@ static time_t ConvertUtc2Secs(struct tm *tm)
seconds += (tm->tm_mday - 1) * SECS_PER_DAY; seconds += (tm->tm_mday - 1) * SECS_PER_DAY;
seconds += tm->tm_hour * SECS_PER_HOUR + tm->tm_min * SECS_PER_MIN + tm->tm_sec; seconds += tm->tm_hour * SECS_PER_HOUR + tm->tm_min * SECS_PER_MIN + tm->tm_sec;
seconds -= tm->__tm_gmtoff; // sub time zone to get UTC time seconds += g_timezone;
return seconds; return seconds;
} }
@ -690,7 +690,7 @@ time_t mktime(struct tm *tmptr)
} }
timeInSeconds = ConvertUtc2Secs(tmptr); timeInSeconds = ConvertUtc2Secs(tmptr);
/* normalize tm_wday and tm_yday */ /* normalize tm_wday and tm_yday */
ConvertSecs2Utc(timeInSeconds, tmptr->__tm_gmtoff, tmptr); ConvertSecs2Utc(timeInSeconds, -g_timezone, tmptr);
return timeInSeconds; return timeInSeconds;
} }