Native/C

[레퍼런스] difftime()

aucd29 2013. 10. 2. 18:48
difftime

원형
double difftime(time_t time2, time_t time1);

헤더파일
time.h

기능
time1, time2가 가리키는 시간의 차이를 초 단위로 계산한다.
time_t는 time.h에 다음과 같이 정의되어 있는 long형 변수이며 보통time()함수에 의해 세트된다.

typedef long time_t

time_t형은 1970년 1월 1일 00:00:00 GMT이후 경과시간을 담는다(타임스템프)

참고함수
time, gettime, asctime

// --------------------------------------------------------

#include <stdio.h>
#include <time.h>
#include <dos.h>
#include <conio.h>

int main(int argc, char *argv[])
{
    time_t first, second;
    
    clrscr();

    printf("press any key after some wait\n");

    first = time(NULL);
    getch();
    second = time(NULL);

    printf("wait time is : %f seconds\n", difftime(second,first));

    getch();
    return 0;
}