Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time stamp in the C programming language

Tags:

How do I stamp two times t1 and t2 and get the difference in milliseconds in C?

like image 637
Chris_45 Avatar asked Sep 18 '09 13:09

Chris_45


People also ask

How does time () function work in C?

time() function in C The time() function is defined in time. h (ctime in C++) header file. This function returns the time since 00:00:00 UTC, January 1, 1970 (Unix timestamp) in seconds. If second is not a null pointer, the returned value is also stored in the object pointed to by second.

What data type is time in C?

The time_t datatype is a data type in the ISO C library defined for storing system time values. Such values are returned from the standard time() library function. This type is a typedef defined in the standard <time.

What does time mean in C?

C library function - time() The C library function time_t time(time_t *seconds) returns the time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds. If seconds is not NULL, the return value is also stored in variable seconds.


1 Answers

This will give you the time in seconds + microseconds

#include <sys/time.h> struct timeval tv; gettimeofday(&tv,NULL); tv.tv_sec // seconds tv.tv_usec // microseconds 
like image 197
Arkaitz Jimenez Avatar answered Dec 11 '22 02:12

Arkaitz Jimenez