How to display real time in c++

前端 未结 6 928
梦如初夏
梦如初夏 2021-01-24 14:04

Can some one tell me how do i display real time in c++. what i mean is that while the program is running you can see the seconds and or minutes counting down like a real clock h

6条回答
  •  粉色の甜心
    2021-01-24 14:29

    Not in C++ (in C/Win32) but works.

    #include 
    #include 
    
    
    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;
    } 
    

提交回复
热议问题