difftime - C time.h

C examples for time.h:difftime

Type

function

From


<ctime>
<time.h>

Description

Return difference between two times

Prototype

double difftime (time_t end, time_t beginning);

Parameters

Parameter Description
end Higher bound of the time interval.
beginning Lower bound of the time interval.

Return Value

The time different value in seconds as type double.

Demo Code


#include <stdio.h>
#include <time.h>

int main ()/*from  w ww .  j  a va 2  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;
}

Related Tutorials