diff --git a/src/fmt/time.c b/src/fmt/time.c index 758cd7b97..d151ee9cb 100644 --- a/src/fmt/time.c +++ b/src/fmt/time.c @@ -143,28 +143,23 @@ int fmt_timestamp_us(struct re_printf *pf, void *arg) { int h, m, s; uint64_t us; -#ifdef WIN32 - SYSTEMTIME st; - - GetSystemTime(&st); - - h = st.wHour; - m = st.wMinute; - s = st.wSecond; - us = st.wMilliseconds; -#else struct timespec tspec; struct tm tm; +#ifdef WIN32 + timespec_get(&tspec, TIME_UTC); + if (!localtime_s(&tm, &tspec.tv_sec)) + return EINVAL; +#else (void)clock_gettime(CLOCK_REALTIME, &tspec); if (!localtime_r(&tspec.tv_sec, &tm)) return EINVAL; +#endif h = tm.tm_hour; m = tm.tm_min; s = tm.tm_sec; us = tspec.tv_nsec / 1000; -#endif (void)arg; return re_hprintf(pf, "%02u:%02u:%02u.%06llu", h, m, s, us);