Current date and time as string

后端 未结 6 1868
梦毁少年i
梦毁少年i 2020-12-04 11:09

I wrote a function to get a current date and time in format: DD-MM-YYYY HH:MM:SS. It works but let\'s say, its pretty ugly. How can I do exactly the sam

6条回答
  •  旧巷少年郎
    2020-12-04 11:53

    Using C++ in MS Visual Studio 2015 (14), I use:

    #include 
    
    string NowToString()
    {
      chrono::system_clock::time_point p = chrono::system_clock::now();
      time_t t = chrono::system_clock::to_time_t(p);
      char str[26];
      ctime_s(str, sizeof str, &t);
      return str;
    }
    

提交回复
热议问题