有人可以告诉我如何在 C++ 中显示实时时间吗?我的意思是,当程序运行时,您可以看到秒和/或分钟倒计时,就像挂在墙上的真实时钟一样
这就是我所拥有的:
int main ()
{
time_t rawtime; //creates and object of the built in time function
struct tm * timeinfo; //no idea what this do
time ( &rawtime ); //gets the time from the computer
timeinfo = localtime ( &rawtime ); //store that time here
//it displays current date and time except time is frozen and not real time
cout<< "Current local time and date: "<<asctime (timeinfo)<< endl;
system("pause");
return 0;
}
不在 C++ 中(在 C/Win32 中),但可以工作。
#include <stdio.h>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
SYSTEMTIME stime; //structure to store system time (in usual time format)
FILETIME ltime; //structure to store local time (local time in 64 bits)
FILETIME ftTimeStamp;
char TimeStamp[256];//to store TimeStamp information
while (true){
////Prepare data needed to output the time stamp:
GetSystemTimeAsFileTime(&ftTimeStamp); // Gets the current system time
FileTimeToLocalFileTime (&ftTimeStamp,<ime);//convert in local time and store in ltime
FileTimeToSystemTime(<ime,&stime);//convert in system time and store in stime
sprintf(TimeStamp, "%d:%d:%d, %d.%d.%d \r",stime.wHour,stime.wMinute,stime.wSecond, stime.wDay,stime.wMonth,stime.wYear);
printf(TimeStamp);
Sleep(1000);
}
system("pause");
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)