How to display real time in c++

前端 未结 6 926
梦如初夏
梦如初夏 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:33

    Below is the a function within a program of mine that displays the current day of week, time (hh:mm) and date (dd/mm/yyy). When I used the SYSTEMTIME struct, I realized the time displayed was four hours too fast, so I resorted to this method. Hope this helps. Intended for Windows users...

    void time()
    {
        cout << "The current date is: ";
        system("date/t");
        cout << "The current time is: ";
        system("time/t");
        cout << "Time zone: ";
        system("tzutil /g");
        cout << endl;
    }
    

    NOTE: This works by querying your system for the date, time, and timezone. Most seasoned programmers do not recommend utilizing the system() tool, but that is ultimately up to you.

提交回复
热议问题