Converting integer time values dd,mm,ss to string showing leading digits

Sorry if this is simple I did google it

I need to generate a string like this dd:hh:mm to pass to a web page.

(based on ESP32 Web Server using Server-Sent Events (SSE) | Random Nerd Tutorials)

I've tried variations on this, which Serial.print s fine, but I'm getting nonsense on the page.

 char statbuff[16];
 // upTime=snprintf(statbuff, 16, " %2i: %2i: %2i:\0",ddUp, hhUp, minsUp);  // OR
  upTime=String(snprintf(statbuff, 16, " %2i: %2i: %2i:\0",ddUp, hhUp, minsUp));
  Serial.println(statbuff);

If i do it like this

upTime = String(ddUp) + ":" + String(hhUp) + ":" + String(minsUp);

it works - but doesnt show leading digits (nor allow two spaces) -
so eg 0:0:9 where I'd want 00:00:09

suggestions?

Use %02i to show the leading zero.
https://cplusplus.com/reference/cstdio/printf/

This prints the number with a field width of 2, but to achieve that, the number will be padded with leading spaces, not leading zeros. You need to use %02i for leading zeros.

Many thanks to both of you. Now looking good