c++ - gmtime is giving me some times localtime? -
c++ - gmtime is giving me some times localtime? -
i'm printing events in multi-thread environment console static mutex shared threads.
the problem randomly every hundred or one thousand events time local time , not utc.
i have seen error in linux machines (build g++) not in windows (build vc++). have no clue start, idea?
void publish(std::string source, std::string topic, std::string msg) noexcept { console.lock(); std::time_t = std::chrono::high_resolution_clock::to_time_t(*localtime); char buf[50]; strftime(buf, sizeof (buf), "%y-%m-%dt%h:%m:%s+00:00", gmtime(&now)); cout << buf << " " << source << " " << topic << " " << msg << endl; cout.flush(); console.unlock(); }
struct tm * gmtime (const time_t * timer);
converts time_t tm utc time. phone call uses value pointed timer fill tm construction values represent corresponding time, expressed utc time (i.e., time @ gmt timezone).
this must working correctly. however, not sure this:
std::time_t = std::chrono::high_resolution_clock::to_time_t(*localtime);
is *localtime giving current time accurately under multithreaded situation? shared variable? instead utilize following:
std::time_t = time(0);
c++ visual-c++ g++
Comments
Post a Comment