【发布时间】:2020-12-30 00:59:27
【问题描述】:
美好的一天!我在 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;
}
【问题讨论】:
-
无法复制。也许不相关的东西是相关的。
标签: c windows-subsystem-for-linux