|
|
|
@@ -63,27 +63,19 @@ std::string GetTimeString() { |
|
|
|
time_t time_seconds = time(0); |
|
|
|
struct tm now_time; |
|
|
|
localtime_s(&now_time, &time_seconds); |
|
|
|
sprintf_s(buf, BUFLEN, "%d-%d-%d %d:%d:%d", now_time.tm_year + 1900, now_time.tm_mon + 1, now_time.tm_mday, |
|
|
|
now_time.tm_hour, now_time.tm_min, now_time.tm_sec); |
|
|
|
snprintf(buf, BUFLEN, "%d-%d-%d %d:%d:%d", now_time.tm_year + 1900, now_time.tm_mon + 1, now_time.tm_mday, |
|
|
|
now_time.tm_hour, now_time.tm_min, now_time.tm_sec); |
|
|
|
#else |
|
|
|
struct timeval cur_time; |
|
|
|
(void)gettimeofday(&cur_time, nullptr); |
|
|
|
|
|
|
|
struct tm now; |
|
|
|
constexpr size_t time_str_len = 19; |
|
|
|
constexpr int64_t time_convert_unit = 1000; |
|
|
|
(void)localtime_r(&cur_time.tv_sec, &now); |
|
|
|
(void)strftime(buf, BUFLEN, "%Y-%m-%d-%H:%M:%S", &now); // format date and time |
|
|
|
// set micro-second |
|
|
|
buf[27] = '\0'; |
|
|
|
int idx = 26; |
|
|
|
auto num = cur_time.tv_usec; |
|
|
|
constexpr int interval_number = 3; |
|
|
|
for (int i = 5; i >= 0; i--) { |
|
|
|
buf[idx--] = static_cast<char>(num % 10 + '0'); |
|
|
|
num /= 10; |
|
|
|
if (i % interval_number == 0) { |
|
|
|
buf[idx--] = '.'; |
|
|
|
} |
|
|
|
} |
|
|
|
snprintf(buf + time_str_len, BUFLEN - time_str_len, ".%03ld.%03ld", cur_time.tv_usec / time_convert_unit, |
|
|
|
cur_time.tv_usec % time_convert_unit); |
|
|
|
#endif |
|
|
|
return std::string(buf); |
|
|
|
} |
|
|
|
|