Get current time in milliseconds, or HH:MM:SS:MMM format

后端 未结 4 628
予麋鹿
予麋鹿 2020-12-01 18:54

I\'ve written a c++ function to get the current time in HH:MM:SS format. How can I add milliseconds or nanoseconds, so I can have a format like HH:MM:SS:M

4条回答
  •  醉梦人生
    2020-12-01 19:47

    This is a cleaner solution using HowardHinnant's date library.

    std::string get_time()
    {
        using namespace std::chrono;
        auto now = time_point_cast(system_clock::now());
        return date::format("%T", now);
    }
    

提交回复
热议问题