How to get current time and date in C++?

后端 未结 24 1476
刺人心
刺人心 2020-11-22 06:55

Is there a cross-platform way to get the current date and time in C++?

24条回答
  •  清酒与你
    2020-11-22 07:29

    you could use C++ 11 time class:

        #include 
        #include 
        using namespace std;
    
        int main() {
    
           time_t now = chrono::system_clock::to_time_t(chrono::system_clock::now());
           cout << put_time(localtime(&now), "%F %T") <<  endl;
          return 0;
         }
    

    out put:

    2017-08-25 12:30:08
    

提交回复
热议问题