This blog is under construction

Saturday, 5 May 2012

difftime example in C

Header file:
    time.h

Synopsis:
     double difftime(time_t t2, time_t t1);

Description:
     It returns the time difference between t1 and t2 in seconds.


difftime function C example:


  #include<stdio.h>
  #include<time.h>
  int main() {
        time_t tp, ret1, ret2;
        double time_diff;
        printf("time(NULL):%ld\n", ret1 = time(NULL));
        sleep(5);
        ret2 = time(&tp);
        printf("Return value: %ld\ntp:%ld\n", ret2, tp);
        time_diff = difftime(ret2, ret1);
        printf("Difftime:%lf\n", time_diff);
        return 0;
  }




  Output:
  jp@jp-VirtualBox:~/cpgms/time$ ./a.out
  time(NULL):1336236391
  Return value: 1336236396
  tp:1336236396
  Difftime:5.000000





No comments:

Post a Comment