C examples for time.h:difftime
function
<ctime> <time.h>
Return difference between two times
double difftime (time_t end, time_t beginning);
Parameter | Description |
---|---|
end | Higher bound of the time interval. |
beginning | Lower bound of the time interval. |
The time different value in seconds as type double.
#include <stdio.h> #include <time.h> int main ()/* www . j a v a2 s . c o m*/ { time_t now; struct tm newyear; double seconds; time(&now); newyear = *localtime(&now); newyear.tm_hour = 0; newyear.tm_min = 0; newyear.tm_sec = 0; newyear.tm_mon = 0; newyear.tm_mday = 1; seconds = difftime(now,mktime(&newyear)); printf ("%.f seconds since new year.\n", seconds); return 0; }