difftime

 

目录

 

函数简介

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;
}