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

后端 未结 24 1937
刺人心
刺人心 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:39

    std::ctime

    Why was ctime only mentioned in the comments so far?

    #include 
    #include 
     
    int main()
    {
        std::time_t result = std::time(nullptr);
        std::cout << std::ctime(&result);
    }
    

    Output

    Tue Dec 27 17:21:29 2011

提交回复
热议问题