我無法獲得UTC時間。隨着測試代碼,我發現,無論gmtime的和localtime將返回相同的結果gmtime_r&localtime_r()在vxworks上返回相同的結果
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);
}
結果是
-> testTimeLib
UTC Time utcTime <2014-12-19T10:57:33>
Local Time localTime <2014-12-19T10:57:33>
通過檢查gmtime_r和則localtime_r的源代碼,我發現,__getZoneInfo被稱爲localtime_r會返回0,這意味着時區爲0,實際上時區應該是GMT + 8。
所以我的問題是我如何設置系統的時區?
http://stackoverflow.com/a/11785853/2410359可能有幫助 – chux 2014-12-19 04:31:55