[英]struct tm becomes PST when passing through a function
Good day, I have a problem with struct tm that is in GMT but when passed through a function, it minuses 8 hours and turns to my local time (PST)美好的一天,我在 GMT 中遇到了 struct tm 的问题,但是当通过一个函数时,它会减少 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(&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(&t);
tm->tm_sec = 0;
char buffx[300];
time_t timeif = timegm(tm);
strftime(buffx, 100, "%Y-%m-%d %H:%M:%S.000", gmtime(&timeif));
//print the buffx
// Prints the time in GMT.
// Do some other unrelated stuff
TestFunction(&unRelatedParameterOne, tm); // Variable tm is in GMT
return 0;
}
I instead pass on time_t timeif to the function now.我现在将 time_t timeif 传递给 function。 This works as time if does not change when passed through a function.如果在通过 function 时没有改变,这将作为时间起作用。
I still do not know why struct tm would change time zone.我仍然不知道为什么 struct tm 会改变时区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.