gmtime的返回不正确小时 [英] gmtime returning incorrect hour
问题描述
我检索GMT时间在C ++ / C。但其返回不正确小时。例如,现在的时刻应该是上午9点,但结构TM
对象返回凌晨3点。任何想法,为什么还是什么我做错了?
time_t的rawtime;
结构TM * PTM;
时间(安培; rawtime);
PTM = gmtime的(安培; rawtime);的std :: stringstream的SS;
SS<< ptm-> tm_hour; //输出3时,它应该是9
gmtime的应该总是返回UTC / GMT时间无论在哪里,用户或他们有什么区设置正确?
gmtime的应该总是返回UTC / GMT时间无论在哪里,用户或他们有什么区设置正确?
块引用>是的,只要他们的计算机时钟设置是否正确。
显然你不是。
I am retrieving the GMT time in c++/c. But its returning the incorrect hour. For example right now the hour should be 9am but the
struct tm
object returns 3am. Any idea why or what I am doing wrong?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 should always return the UTC/GMT time regardless of where the user is or what timezone setting they have right?
解决方案gmtime should always return the UTC/GMT time regardless of where the user is or what timezone setting they have right?
Yes, as long as their computer clock is set correctly.
Evidently yours is not.
这篇关于gmtime的返回不正确小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!