How to display RelativeTime in HH:MM:SS format?

This might be a silly question but I’m struggling to display RelativeTime in a HH:MM:SS format - there is an event which is triggered by a user and I’m just trying to show how long since the user started the event.

I can calculate the delta just fine but it’s the String formatting I’m having issues with. For example: If I use the “inSeconds” method, it will start counting from 0 which is fine but then it goes past 60 since it’s just showing the absolute total amount of seconds from N, which is not what I want - I’m looking to build it in a human readable format so that once it hits 60s, then it increase the minute timer, and the SS starts counting from 0 again.

Any advice appreciated!

Maybe something like this to start with

auto timeSec = juce::RelativeTime::seconds(timePassed);

auto sD = (int)timeSec.inSeconds() % 60;
auto mD = (int)timeSec.inMinutes() % 60;
auto hD = (int)timeSec.inHours();

std::ostringstream s1;
s1 << std::setw(2) << std::setfill('0') << sD;
std::string ss1 = s1.str();

std::ostringstream m1;
m1 << std::setw(2) << std::setfill('0') << mD;
std::string mm1 = m1.str();

juce::String timePassedFormated = "Time: " + juce::String(hD) + ":" + mm1 + ":" + ss1;

Mod 60 of course! Cheers :slight_smile: