Questions tagged [timeval]
56 questions
15
votes
2 answers
Is there a standard way to convert a struct timeval into a struct timespec?
struct timeval represents and instant in time with two members, tv_sec (seconds) and tv_usec (microseconds). In this representation, tv_usec is not by itself an absolute time it is a sub second offset off of tv_sec.
struct timespec works the same…

dicroce
- 45,396
- 28
- 101
- 140
14
votes
4 answers
How do I compare two timestamps in C?
I'm writing a socket program that maintains FIFO queues for two input sockets. When deciding which queue to service, the program pulls the most recent time-stamp from each queue.
I need a reliable method for comparing two timeval structs. I tried…

Vishal Kotcherlakota
- 1,134
- 4
- 13
- 36
12
votes
5 answers
Reinitialize timeval struct
How can I reinitialize a timeval struct from time.h?
I recognize that I can reset both of the members of the struct to zero, but is there some other method I am overlooking?

BSchlinker
- 3,401
- 11
- 51
- 82
7
votes
2 answers
How to convert std::chrono::system_clock::duration into struct timeval
The title says it all.
I have to implement a function that receives a std::chrono::system_clock::duration value and that needs to convert it into a timeval sruct so I can pass it to some system function.

chmike
- 20,922
- 21
- 83
- 106
4
votes
2 answers
Porting time APIs from Linux to Visual Studio 2008
I have an application that I am porting to Microsoft Visual Studio 2008 that builds and runs fine on Linux.
I am having trouble with the time routines, my Linux code looks like this:
#include
#include
typedef long long…

WilliamKF
- 41,123
- 68
- 193
- 295
4
votes
2 answers
C - timeval to uint64_t
Morning!
I'm trying to get a nanosecond timestamp (uint64_t) from a timeval struct.
struct timeval t;
// initialized so that ....
print("t sec: %ld, micro sec: %ld", t.tv_sec, t.tv_usec);
// .... prints "t sec: 4, micro sec:…

Noel93
- 135
- 11
4
votes
2 answers
convert month/day/year/time to timeval in C/C++
In C/C++, suppose I have the following values:
int year = 2010;
int month = 6;
int day = 15;
int hour = 14;
int minute = 52;
int seconds = 34;
int microseconds = 141231;
What's the easiest way to convert this to a timeval? I think timeval is time…

user8125
- 915
- 2
- 7
- 6
4
votes
2 answers
Using struct timeval in Python
I have a C program containing a structure
struct S{
int x;
struct timeval t;
};
and a function
int func(struct S s1, struct S s2)
I need to call this function from my python program.
I am using ctypes.The parallel structure…

Sudip
- 523
- 2
- 7
- 14
3
votes
3 answers
Get time_t / timeval corresponding to ( local_timezone ) midnight on a given date
Given a time_t or struct timeval, how do I get the timeval or time_t of midnight EST/EDT ( local timezone ) on that day ?
As in assuming local timezone is EST/EDT, given a time_t corresponding to say 2010-11-30 08:00:00 EST/EDT, the expected answer…

Humble Debugger
- 4,439
- 11
- 39
- 56
3
votes
3 answers
Is there a benefit in using unsigned long for timeval members?
I noticed some programmers use unsigned long for tv_sec and tv_usec [when they copy them or operate with them] of timeval while they are defined as simply long.
Though it does make me wonder why they were defined like that when time usually goes…

j riv
- 3,593
- 6
- 39
- 54
3
votes
2 answers
c++ setting timeval members
I have a function which takes two current class level member variables and sets them into a timeval structure, and returns the timeval obj (by value).
I am seeing an issue when setting a class level member timeval object vs creating a new timeval…

donalmg
- 627
- 5
- 15
- 22
3
votes
1 answer
How getrusage works and What is really inside the rusage struct?
I'm trying to understand how
int getrusage(int who, struct rusage* usage)
works in order to calculate the running time of one my program. I red the man page, 10 times maybe, and still can't get it. Tried to find something on the web, but nothing…

Root149
- 389
- 1
- 3
- 11
3
votes
1 answer
how to calculate milliseconds using timeval structure?
I want to retrieve values in milliseconds from a variable of type timeval. Below is my attempt:
timeval* time;
long int millis = (time->tv_sec * 1000) + (time->tv_usec / 1000);
printf("Seconds : %ld, Millis : %ld", time->tv_sec, millis);
Output =>…

sam18
- 631
- 1
- 10
- 24
2
votes
2 answers
timeval not returning expecting results
I have some code shown below:
#include
#include
typedef struct{
struct timeval timestamp;
}teststruct;
class TestClass {
public:
TestClass();
void dosomething(int,…

wtabib
- 19
- 1
2
votes
1 answer
convert timeval structure to c#
I know this question may be so simple, I have the following code and it should be converted to C#, but the main problem is that I can not understand what below code is doing exactly!!!!...I've searched but I did not find any thing..I Think may be…

Paridokht
- 1,374
- 6
- 20
- 45