linux 获得对当前系统时间 延时30秒停止运行
例子:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main()
{
time_t start ,end ;
time(&start);
int delay_time=3; //设置测量时间30s
double cost;
int cost_time;
while (1)
{
printf("1");
time(&end);
cost=difftime(end,start);// double difftime(time_t time1, time_t time2) 返回 time1 和 time2 之间相差的秒数 (time1 - time2)
cost_time=(int) cost ;
if (cost_time==delay_time)
{
printf ("运行了%d秒",delay_time);
break ;
}
}
return 0;
}