> Tommi Mäkitalo <[email protected]> hat am 10. August 2013 um 01:04 geschrieben: [...] > Do not use localtime in tntnet applications. It is not thread safe. > localtime_r is the thread safe variant. > > And for formatting there is strftime: > > cxxtools::DateTime dt(2013, 5, 15, 0, 0, 0); > > struct tm timeinfo; > timeinfo.tm_year = dt.year(); > timeinfo.tm_mon = dt.month() - 1; > timeinfo.tm_mday = dt.day(); > timeinfo.tm_wday = 0; > timeinfo.tm_hour = dt.hour(); > timeinfo.tm_min = dt.minute(); > timeinfo.tm_sec = dt.second(); > timeinfo.tm_isdst = 0; > time_t t = mktime(&timeinfo); // somewhat strange to use mktime to > convert tm to time_t and localtime_r back to tm but we need the day of week > localtime_r(&t, &timeinfo); > char buffer[80]; > strftime(buffer, sizeof(buffer), "%a, %d %b %y %T %z", &timeinfo); > std::cout << buffer << std::endl;
Great, that's a too small mistakes: timeinfo.tm_year = ( cxxdt.year() - 1900 ); and strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %z", &timeinfo); but else working fine! Olaf -------------------|-------------------|-------------------|-------------------| ------------------------------------------------------------------------------ Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk _______________________________________________ Tntnet-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tntnet-general
