This commit is contained in:
2024-01-13 17:19:37 +08:00
parent b6db76625b
commit 841bcc3998
6 changed files with 36 additions and 0 deletions

View File

@@ -63,3 +63,18 @@ time_t time_util::timegm(struct tm* tm) {
return now + get_timezone();
#endif
}
time_t time_util::time_ns() {
#if _WIN32
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
time_t t = ((size_t)ft.dwHighDateTime << 32) | (size_t)ft.dwLowDateTime;
return t;
#elif HAVE_CLOCK_GETTIME
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec * 1000000000LL + ts.tv_nsec;
#else
return time(NULL) * 1000000000LL;
#endif
}