#c #windows-subsystem-for-linux
#c #windows-subsystem-for-linux
Вопрос:
Добрый день! У меня проблема со структурой tm, которая находится в GMT, но при передаче через функцию она минусует 8 часов и переходит на мое местное время (PST)
void TestFunction(glob_t* globbuf, struct tm *tm)
{
char buffx[300];
time_t timeif = timegm(tm);
strftime(buffx, 100, "%Y-%m-%d %H:%M:%S.000", gmtime(amp;timeif));
//print the buffx
// the print shows the time in PST, -8 hours from what it was because at this point tm becomes
// PST
}
int main()
{
time_t t = time(NULL);
struct tm *tm = gmtime(amp;t);
tm->tm_sec = 0;
char buffx[300];
time_t timeif = timegm(tm);
strftime(buffx, 100, "%Y-%m-%d %H:%M:%S.000", gmtime(amp;timeif));
//print the buffx
// Prints the time in GMT.
// Do some other unrelated stuff
TestFunction(amp;unRelatedParameterOne, tm); // Variable tm is in GMT
return 0;
}
Комментарии:
1. Невозможно воспроизвести. Возможно , связан несвязанный материал .
Ответ №1:
Вместо этого я передаю time_t timeif функции now . Это работает как время, если не изменяется при передаче через функцию.
Я до сих пор не знаю, почему struct tm изменит часовой пояс.