Reputation: 131
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?
Upvotes: 0
Views: 1543
Reputation: 385274
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.
Upvotes: 1