Function name : difftime
Header file : <time.h>
Function prototype : double difftime(time_t time1, time_t time2);
Function: Calculate the time difference between two moments
Parameters : time_t time1 time_t object representing the end of time
time_t time2 time_t object representing the start of time
Return value : This function returns the number of seconds between two times (time1 - time2) expressed as a double precision floating point value.
Program example : Get the time difference between two moments and output the result
#include<windows.h>#include<stdio.h>#include<time.h>#include<conio.h>intmain(void){time_tfirst,second;//typedeftime_tlongfirst=time(NUL L);//Get the current system time Sleep(2000);//Interval 2ssecond=time(NULL);//Get the current system time printf(Thedifferenceis:%fsecondsn,difftime(second,first));getch() ;return0;}
Running results:
Thedifferenceis:2.000000seconds