1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/time.cpp
2018-10-03 03:33:28 -07:00

32 lines
693 B
C++

#include <llarp/time.h>
#include <time.h>
#include <sys/time.h>
// these _should_ be 32-bit safe...
llarp_time_t
llarp_time_now_ms()
{
struct timeval tv;
struct timezone z;
z.tz_minuteswest = 0;
time_t t = time(nullptr);
z.tz_dsttime = gmtime(&t)->tm_isdst;
gettimeofday(&tv, &z);
llarp_time_t timeNow =
(llarp_time_t)(tv.tv_sec) * 1000 + (llarp_time_t)(tv.tv_usec) / 1000;
return timeNow;
}
llarp_seconds_t
llarp_time_now_sec()
{
struct timeval tv;
struct timezone z;
z.tz_minuteswest = 0;
time_t t = time(nullptr);
z.tz_dsttime = gmtime(&t)->tm_isdst;
gettimeofday(&tv, &z);
llarp_time_t timeNow = tv.tv_sec;
return timeNow;
}