difftime function finds out the difference in seconds between two times

Syntax

C difftime function has the following syntax.

double difftime(time_t time2, time_t time1);

C difftime function is from header file time.h.

Description

C difftime function returns the difference, in seconds, between time1 and time2( time2 - time1).

Example

Use C difftime function to find out the difference in seconds between two times.


#include <time.h>
#include <stdio.h>
//from  w  w w.j  av a  2 s.c  om
int main(void)
{
  time_t start, end;
  volatile long unsigned t;

  start = time(NULL);
  for(t=0; t<500; t++) ;
  end = time(NULL);
  printf("Loop used %f seconds.\n", difftime(end, start));

  return 0;
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h