Formatting seconds as days hours minutes seconds
Try this. It uses a string-based stream to do formatted output. Let the stream put in leading zeroes. When you're done with your output, the str() method returns (a copy of) the embedded string.

#include &lt;time.h&gt;
#include &lt;sstream&gt;
#include &lt;iomanip&gt;

std::string eta_string ( int64_t s )
{
    time_t seconds ( s );
    tm p;
    gmtime_s ( &amp;p, &amp;seconds );

    std::ostringstream os;

    if ( p.tm_yday &gt; 0 )
        os &lt;&lt; p.tm_yday &lt;&lt; (p.tm_yday == 1 ? " day " : " days ");

    os &lt;&lt; std::setfill('0') &lt;&lt; std::setw(2) &lt;&lt; p.tm_hour &lt;&lt; ':' &lt;&lt;
        std::setfill('0') &lt;&lt; std::setw(2) &lt;&lt; p.tm_min &lt;&lt; ':' &lt;&lt;
        std::setfill('0') &lt;&lt; std::setw(2) &lt;&lt; p.tm_sec;

    return os.str();
}