double difftime (time_t end, time_t beginning);
Return difference between two times
Calculates the difference in seconds between beginning and end.
time_t is an alias of a fundamental arithmetic type capable of representing times as returned by function time.
- Higher bound of the time interval whose length is calculated.
- Lower bound of the time interval whose length is calculated.
If this describes a time point later than end, the result is negative.
The result of
(end-beginning) in seconds as a floating-point value of type
/* difftime example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, struct tm, difftime, time, mktime */
int main ()
struct tm newyear;
time(&now); /* get current time; same as: now = time(NULL) */
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 in the current timezone.\n", seconds);
3777291 seconds since new year in the current timezone.
Concurrently calling this function is safe, causing no data races.
No-throw guarantee: this function never throws exceptions.
- Convert tm structure to string (function)
- Convert time_t to tm as UTC time (function)
- Convert time_t to tm as local time (function)
- Get current time (function)