Formatted displays on I2C -LCD ( 16 x 2 type LCD)

I am reading the time value using a DS1307 chip.

Printing it on LCD with code as below :

void displayTime(void)
{
   ReadTime();
   lcd.clear();
   lcd.write( "PRDN.MON.SYSTEM." );
   lcd.setCursor(4,1);  
   lcd.print( hour );
   lcd.setCursor(6,1);
   lcd.print(":");
   lcd.setCursor(7,1);  
   lcd.print( minute );
   lcd.setCursor(9,1);
   lcd.print(":");
   lcd.setCursor(10,1);  
   lcd.print( second);
   disp_count = 0;
 }

As an example when the time is 5 hours, 5 minutes and 5 seconds its printing like this 5: 5: 5

But I will be happy to get it print as 05:05:05. Problem is how to tell the UNO ??

But I will be happy to get it print as 05:05:05. Problem is how to tell the UNO ??

An often asked question.

char timeString[20];
sprintf(timeString, "%02d:%02d:02d", hour, minute, second);
lcd.print(timeString);

As an alternative:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  char buff[5];
  int hour = 5;
  int minute = 15;
  int second = 5;
   
  PadValue(buff, hour);
  Serial.print(buff);
  Serial.print(":");
  
  PadValue(buff, minute);
  Serial.print(buff);
  Serial.print(":");
  
  PadValue(buff, second);
  Serial.print(buff);
  Serial.println();

}

void PadValue(char str[], int num)
{
  itoa(num, str, 10);
  if (strlen(str) == 1) {
    str[2] = '\0';
    str[1] = str[0];
    str[0] = '0';
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

PaulS's code needs a "%" added before the last conversion expression (e.g., "%2d"). After that change and using the Serial monitor as output, the code takes 3276 bytes. The version above uses 2066 bytes. A good part of the difference is because sprintf() is such a powerful and flexible function it often has more features than one program uses. It's the old H-bomb-to-kill-an-ant issue. While the source code "looks" like more code, the compiled code is considerably less.