struct tm 在通过函数时变为 PST

struct tm becomes PST when passing through a function

美好的一天!我在格林威治标准时间的 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;
}

我现在将 time_t timeif 传递给函数。如果在通过函数时不发生变化,这就相当于时间。

我仍然不知道为什么struct tm会改变时区。