C Library Function - difftime() Last Updated : 06 May, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 ValueReturns the difference between time1 and time2 (as measured in seconds).Example of difftime() in C C // C program to demonstrate working of difftime() #include <stdio.h> #include <time.h> #include <unistd.h> // Driver Code 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; } OutputDifference is 6.00 secondsException in difftime()It never throws an exception. Comment More infoAdvertise with us Next Article C Library Function - difftime() S Shivani Ghughtyal Follow Improve Article Tags : Misc C Language date-time-program C-Library C Library Functions +1 More Practice Tags : Misc Similar Reads asctime() function in C++ The asctime() function is defined in the ctime header file. The asctime() function converts the given calendar time of structure tm to a character representation i.e human readable form. Syntax: char* asctime(const struct tm * time_ptr); Parameter: This function accepts single parameter time_ptr i.e 1 min read PHP | date_diff() Function The date_diff() is an inbuilt function in PHP which is used to calculate the difference between two dates. This function returns a DateInterval object on the success and returns FALSE on failure. Syntax: date_diff($datetime1, $datetime2); Parameters: The date_diff() function accepts two parameters a 2 min read PHP | filectime( ) Function The filectime() function in PHP is an inbuilt function which is used to return the last time the specified file was changed. The filectime() function returns the last time the file was changed as a Unix Timestamp on success and False on failure. The filectime() function checks for inode changes whic 2 min read clock() function in C The clock() function in C returns the approximate processor time that is consumed by the program which is the number of clock ticks used by the program since the program started. The clock() time depends upon how the operating system allocates resources to the process that's why clock() time may be 2 min read strftime() function in C/C++ strftime() is a function in C which is used to format date and time. It comes under the header file time.h, which also contains a structure named struct tm which is used to hold the time and date. The syntax of strftime() is as shown below : size_t strftime(char *s, size_t max, const char *format, c 3 min read Like