[ACCEPTED]-Convert timeval to time_t-c
Accepted answer
time_t
just stores seconds, so
time_t time = (time_t)ut_tv.tv_sec;
Should work, but 3 since you're just looking for a difference, there's 2 always the magic of subtraction.
struct timeval diff = {a.tv_sec-b.tv_sec, a.tv_usec-b.tv_usec};
This lets you keep 1 all the precision you had before.
Without using c-cast, you can simply do 1 this :
struct timeval rawtime_s_us;
gettimeofday( &rawtime_s_us, NULL );
time_t rawtime_s = rawtime_s_us.tv_sec;
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.