【发布时间】:2016-07-29 09:35:36
【问题描述】:
我正在用 c++/c 检索 GMT 时间。但它返回的时间不正确。例如,现在时间应该是上午 9 点,但 struct tm 对象返回凌晨 3 点。知道为什么或我做错了什么吗?
time_t rawtime;
struct tm* ptm;
time(&rawtime);
ptm = gmtime(&rawtime);
std::stringstream ss;
ss << ptm->tm_hour; // outputs "3" when it should be "9"
gmtime 应该始终返回 UTC/GMT 时间,而不管用户在哪里或他们的时区设置是否正确?
【问题讨论】:
-
无法复制:ideone.com/K9116G
-
我试过了,感觉还不错,ideone
-
一些用户习惯将他们的计算机保持在UTC,而是将时间设置为本地时间。你能验证你是否在你认为的 gmt 上吗?
-
什么是“c++/c”?对我来说,这看起来像(单调的)C++。 C 没有
std::stringstream。std::chrono有什么问题?