lokinet/llarp/time.cpp

32 lines
693 B
C++
Raw Normal View History

2018-01-29 14:27:24 +00:00
#include <llarp/time.h>
2018-10-02 15:32:07 +00:00
#include <time.h>
#include <sys/time.h>
2018-01-19 16:51:27 +00:00
// these _should_ be 32-bit safe...
llarp_time_t
llarp_time_now_ms()
{
struct timeval tv;
struct timezone z;
z.tz_minuteswest = 0;
2018-10-03 10:33:28 +00:00
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;
2018-01-29 14:27:24 +00:00
}
llarp_seconds_t
llarp_time_now_sec()
{
struct timeval tv;
struct timezone z;
z.tz_minuteswest = 0;
2018-10-03 10:33:28 +00:00
time_t t = time(nullptr);
z.tz_dsttime = gmtime(&t)->tm_isdst;
gettimeofday(&tv, &z);
llarp_time_t timeNow = tv.tv_sec;
return timeNow;
2018-01-29 14:27:24 +00:00
}