difftime返回值的单位是秒吗?
- C/C++ code
#include "stdlib.h"#include "time.h"int main(void){ time_t first, second; first = time(NULL); second = time(NULL); printf("%f", difftime(second, first)); return 0;}
这样的程序输出的是1.000000. 问题是这样子要运行1秒之久么....
不解,球解答,谢谢了
[解决办法]
这种简单的问题,写一个简单的函数测试一下就行了;
- C/C++ code
#include <time.h>#include <stdio.h>int main(void){ time_t first, second; first = time(NULL); /* Gets system time */ sleep(2); /* Waits 2 secs */ second = time(NULL); /* Gets system time again */ printf("The difference is: %f seconds\n",difftime(second,first)); return 0;}[root@bogon temp]# ./t1The difference is: 2.000000 seconds测试证明,返回的是秒