Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top