函式簡介
C語言函式difftime
功 能:返回兩個time_t型變數之間的時間間隔,即 計算兩個時刻之間的時間差。
用 法: double difftime(time_t time2, time_t time1);
頭檔案:time.h
舉例
程式例1:(在vc++6.0中運行通過)
#include <time.h>
#include <stdio.h>
#include <process.h>
#include <windows.h>
int main(void)
{
time_t first, second;
system("cls");
first = time(NULL);
Sleep(2000);
second = time(NULL);
printf("The difference is: %f seconds\n",difftime(second,first));
return 0;
}
程式例2:(在TC中運行通過)
#include <time.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
int main(void)
{
time_t first, second;
clrscr();
first = time(NULL); /* Gets system
time */
delay(2000); /* Waits 2 secs */
second = time(NULL); /* Gets system time
again */
printf("The difference is: %f \
seconds\n",difftime(second,first));
getch();
return 0;
}