Formatting seconds as days hours minutes seconds I have the below and it gives me the desired output (ie; 1 day 12:05:33) but it looks overly complicated, is there a more straight forward way of doing this with the least amount of string concatenations?

     std::string eta_string ( int64_t s ) {

     time_t seconds ( s );
     tm p;
     gmtime_s ( &amp;p , &amp;seconds );
     std::string str;

     if ( p.tm_yday &gt; 0 ) {
      if ( p.tm_yday == 1 ) {
        str = std::to_string ( p.tm_yday ) += " day ";
      } else {
        str = std::to_string ( p.tm_yday ) += " days ";
      }
      if ( p.tm_hour &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_hour ) += ":";
      } else {
        str = str += std::to_string ( p.tm_hour ) += ":";
      }
      if ( p.tm_min &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_min ) += ":";
      } else {
        str = str += std::to_string ( p.tm_min ) += ":";
      }
      if ( p.tm_sec &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_sec );
      } else {
        str = str += std::to_string ( p.tm_sec );
      }
     }
     else if ( p.tm_hour &gt; 0 ) {
      if ( p.tm_hour &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_hour ) += ":";
       } else {
        str = str += std::to_string ( p.tm_hour ) += ":";
       }
       if ( p.tm_min &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_min ) += ":";
       } else {
        str = str += std::to_string ( p.tm_min ) += ":";
       }
       if ( p.tm_sec &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_sec );
       } else {
        str = str += std::to_string ( p.tm_sec );
       }
     } else if ( p.tm_min &gt; 0 ) {
      str = "00:";
      if ( p.tm_min &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_min ) += ":";
      } else {
        str = str += std::to_string ( p.tm_min ) += ":";
      }
      if ( p.tm_sec &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_sec );
      } else {
        str = str += std::to_string ( p.tm_sec );
      }
     } else {
      str = "00:00:";
      if ( p.tm_sec &lt; 10 ) {
        str = str.append ( "0" ) += std::to_string ( p.tm_sec );
      } else {
        str = str += std::to_string ( p.tm_sec );
      }
    }
    return str;
 }
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();
}