这里直接使用了 localtime 函数获取 tm 时间然后做显示。代码如下:
#include <iostream>
#include <windows.h>
#include "time.h"
#include <process.h>
using namespace std;
void Clock()
{
struct tm *ptr;
time_t lt = time(NULL);
ptr = localtime(<);
cout<<"It is--- ";
cout.setf(ios::right);
cout.width(2);
cout.fill('0');
cout<<ptr->tm_hour;
cout<<":";
cout.setf(ios::right);
cout.width(2);
cout.fill('0');
cout<<ptr->tm_min;
cout<<":";
cout.setf(ios::right);
cout.width(2);
cout.fill('0');
cout<<ptr->tm_sec;
cout<<" ---now."<<endl;
}
int main()
{
while(true)
{
system("cls");
Clock();
Sleep(1000);
}
return 0;
}