码迷,mamicode.com
首页 > 其他好文 > 详细

即时显示时间

时间:2015-06-26 19:29:18      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 1 #include <iostream>
 2 #include <iomanip>
 3 #include <ctime>
 4 #include <windows.h>
 5 using namespace std;
 6 int main()
 7 {
 8 time_t ti = time(NULL);
 9 struct tm* timer = localtime(&ti);
10 while(1)
11 {
12 cout << setfill(0) << setw(2) << timer->tm_hour << ":" <<setw(2) << timer->tm_min << ":" << setw(2) << timer->tm_sec << "\r";
13 Sleep(1000);//睡眠一秒钟
14 if(++timer->tm_sec >= 60)//
15 {
16      timer->tm_sec = 0;
17      if(++timer->tm_min >= 60)//
18 {
19      timer->tm_min = 0;
20      if(++timer->tm_hour >= 24)//
21         timer->tm_hour = 0;
22 }
23 }
24 }
25 return 0;
26 }
View Code

 

即时显示时间

标签:

原文地址:http://www.cnblogs.com/bmyell1234/p/4602868.html

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