VOOZH about

URL: https://www.geeksforgeeks.org/c/difftime-library-function-in-c/

⇱ C Library Function - difftime() - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Library Function - difftime()

Last Updated : 6 May, 2023

The difftime() is a C Library function that returns the difference in time, in seconds(i.e. ending time - starting time). It takes two parameters of type time_t and computes the time difference in seconds. The difftime() function is defined inside the <time.h> header file.

Syntax

The syntax of difftime() function is as follows:

double difftime(time_t time2, time_t time1);

Parameters

The difftime() function takes two parameters:

  • time1: Lower bound of the time interval whose length is calculated.
  • time2: Higher bound of the time interval whose length is calculated.

where time1 and time2 are variables of type time_t which is a predefined structure for calendar times.

Return Value

  • Returns the difference between time1 and time2 (as measured in seconds).

Example of difftime() in C


Output
Difference is 6.00 seconds

Exception in difftime()

  • It never throws an exception.
Comment