The C library function difftime() returns the difference, in seconds between starting time and ending time.(ending time-starting time)
// It is present in time.h header file
#include
Syntax :
double difftime(time_t time2, time_t time1);
Parameters:
time1 : Lower bound of the time interval
whose length is calculated.
time2 : Higher bound of the time interval
whose length is calculated.
Return value :
Returns the difference between time1 and
time2 (as measured in seconds).
// C program to demonstrate working of // difftime() #include <time.h> #include <stdio.h> #include <unistd.h> int main() { int sec; time_t time1, time2; // Current time time(&time1;); for (sec = 1; sec <= 6; sec++) sleep(1); // time after sleep in loop. time(&time2;); printf("Difference is %.2f seconds", difftime(time2, time1)); return 0; } |
chevron_right
filter_none
Output:
Difference is 6.00 seconds
This article is contributed by Shivani Ghughtyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- difftime() function in C++
- How to print range of basic data types without any library function and constant in C?
- isgraph() C library function
- wcstof function in C library
- Unordered Sets in C++ Standard Template Library
- Advanced C++ with boost library
- Inbuilt library functions for user Input | scanf, fscanf, sscanf, scanf_s, fscanf_s, sscanf_s
- How to add "graphics.h" C/C++ library to gcc compiler in Linux
- The C++ Standard Template Library (STL)
- List in C++ Standard Template Library (STL)
- Deque in C++ Standard Template Library (STL)
- Map in C++ Standard Template Library (STL)
- Wide char and library functions in C++
- C Library math.h functions
- wprintf() and wscanf in C Library
- snprintf() in C library
- boost::split in C++ library
- <iterator> library in C++ STL
- Factorial of Large Number Using boost multiprecision Library
- Difference between Header file and Library

