#include <time.h>
time_t time(time_t *tloc);
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main()
{
int i;
time_t the_time;
for(i = 1; i <= 10; i++) {
the_time = time((time_t *)0);
printf("The time is %ld\n", the_time);
sleep(2);
}
exit(0);
}
[root@localhost C]# ./envtime.exe
The time is 1235037957
The time is 1235037959
The time is 1235037961
The time is 1235037963
The time is 1235037965
The time is 1235037967
The time is 1235037969
The time is 1235037971
The time is 1235037973
The time is 1235037975
#include <time.h>
double difftime(time_t time1, time_t time2);
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main()
{
time_t the_time_1;
time_t the_time_2;
the_time_1 = time((time_t *)0);
printf("The time is %ld\n", the_time_1);
sleep(2);
the_time_2 = time((time_t *)0);
printf("The time is %ld\n", the_time_2);
printf("Difftime returns is: %e\n", difftime(the_time_2, the_time_1));
exit(0);
}
[root@localhost C]# ./envtime.exe
The time is 1235044467
The time is 1235044469
Difftime returns is: 2.000000e+00
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |