You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/time.cpp

32 lines
669 B
C++

7 years ago
#include <llarp/time.h>
6 years ago
#include <time.h>
#include <sys/time.h>
7 years ago
// 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;
7 years ago
}
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;
7 years ago
}