码迷,mamicode.com
首页 > 编程语言 > 详细

c++ 实现等待5s

时间:2019-05-24 10:50:13      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:tar   div   localtime   %s   ==   color   puts   span   int   

 

#include <stdio.h>      /* puts, printf */
#include <time.h>       /* time_t, struct tm, time, localtime */
int main ()
{
    struct tm * timeinfo;
    double seconds;
    time_t start_time,now;
    
    time (&start_time);
    
    while(1){
        time (&now);
        seconds = difftime(now,start_time);
        if(seconds==5){
            break;
        }
    }
    
    timeinfo = localtime (&start_time);
    printf ("start_time local time and date: %s", asctime(timeinfo));
    timeinfo = localtime (&now);
    printf ("now local time and date: %s", asctime(timeinfo));
    
    printf("time spend %f\n",seconds);
    return 0;
}

输出

start_time local time and date: Fri May 24 10:24:40 2019
now local time and date: Fri May 24 10:24:45 2019
time spend 5.000000

 

c++ 实现等待5s

标签:tar   div   localtime   %s   ==   color   puts   span   int   

原文地址:https://www.cnblogs.com/sea-stream/p/10916525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!