I have a trouble about get the UTC time. With the test code, I found that both gmtime and localtime would return the same result
void testTimeLib()
{
struct tm utcTime, localTime;
time_t now;
char utcStr[80], localStr[80];
time(&now);
gmtime_r(&now, &utcTime);
localtime_r(&now, &localTime);
memset(utcStr, 0, sizeof(utcStr));
strftime(utcStr, sizeof(utcStr), "%Y-%m-%dT%H:%M:%S", &utcTime);
memset(localStr, 0, sizeof(localStr));
strftime(localStr, sizeof(localStr), "%Y-%m-%dT%H:%M:%S", &localTime);
printf("UTC Time\tutcTime <%s>\n", utcStr);
printf("Local Time\tlocalTime <%s>\n", localStr);
}
the result is
-> testTimeLib
UTC Time utcTime <2014-12-19T10:57:33>
Local Time localTime <2014-12-19T10:57:33>
By checking the source code of gmtime_r and localtime_r, I found that __getZoneInfo called by localtime_r would return 0 which means the timezone is 0, actually the timezone should be GMT+8.
So my question is how I can set the timezone to system?