I have a function which accepts second as argument and returns a string in HH:MM:SS format. Without std::chrono, I can implement it like this:
string myclass::ElapsedTime(long secs) {
uint32_t hh = secs / 3600;
uint32_t mm = (secs % 3600) / 60;
uint32_t ss = (secs % 3600) % 60;
char timestring[9];
sprintf(timestring, "%02d:%02d:%02d", hh,mm,ss);
return string(timestring);
}
Using std::chrono
, I can convert the argument to std::chrono::seconds sec {seconds};
.
But the how can I convert it to string with the format? I saw the good video tutorial from Howard Hinnant in https://youtu.be/P32hvk8b13M. Unfortunately, there is no example for this case.