Skip to content

Commit 8e2fb19

Browse files
committed
Improve getLocalTimeString a bit
1 parent 13b3f91 commit 8e2fb19

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

include/kafka/Utility.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ namespace KAFKA_API::utility {
1919
*/
2020
inline std::string getLocalTimeString(const std::chrono::system_clock::time_point& timePoint)
2121
{
22-
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(timePoint.time_since_epoch()) % 1000000;
2322
auto time = std::chrono::system_clock::to_time_t(timePoint);
24-
25-
std::ostringstream oss;
2623
std::tm tmBuf = {};
24+
2725
#if !defined(WIN32)
28-
oss << std::put_time(localtime_r(&time, &tmBuf), "%F %T") << "." << std::setfill('0') << std::setw(6) << micros.count();
26+
localtime_r(&time, &tmBuf);
2927
#else
3028
localtime_s(&tmBuf, &time);
31-
oss << std::put_time(&tmBuf, "%F %T") << "." << std::setfill('0') << std::setw(6) << micros.count();
3229
#endif
30+
31+
std::ostringstream oss;
32+
oss << std::put_time(&tmBuf, "%F %T") << "." << std::setfill('0') << std::setw(6)
33+
<< std::chrono::duration_cast<std::chrono::microseconds>(timePoint.time_since_epoch()).count() % 1000000;
34+
3335
return oss.str();
3436
}
3537

0 commit comments

Comments
 (0)