difftime() returning incorrect values

I am using difftime() to compare two time_t values.If the diffrence between the two is 6 secs, difftime returns as 3606

Please give me ideas on where I am doing a mistake.
How could we help you if you don't post your code ?

I tried this code and it works as expected (Linux 2.6.28.16, g++ 4.3.3, libc6 v2.9):

1
2
3
4
5
6
7
8
9
10
11
#include <time.h>
#include <unistd.h>
#include <iostream>

int main(void)
{
    time_t t1 = time(NULL);
    usleep(6000000);
    time_t t2 = time(NULL);
    std::cout << difftime(t2, t1) << std::endl;
}

Last edited on
Topic archived. No new replies allowed.