Safari
Safari

Reputation: 11935

C++ timestamp and diffTime

I'm trying to know the timestamp when I receive a message. I should check if it has been N seconds of receiving the last message. I'm using time_t. I take the current time like this: time (& myTime);

how can I check if they spent more than N seconds?

Is there a way to know the number of seconds (timestamp) of a total time_t?

Upvotes: 0

Views: 535

Answers (1)

Colin D Bennett
Colin D Bennett

Reputation: 12084

You ask the "number of seconds" of a time_t. This would be absolute time. You'd want probably then want to format it using localtime() or some such function in hour/minute/second, day/month/year form.

If you want to know the time since a previous event, you should simply save the time_t from that event and then use a statement like if (difftime(thisevent_time, lastevent_time) > max_seconds) to handle it.

Upvotes: 2

Related Questions