Time and Date displaying

I'm using a standard 16x2 LCD shield and want to display date and time. When the seconds hit 00 again and counts up it only uses 1 cell so it will display '1', '2' etc. How do I get it to count up using two cells like '01', '02', '03' and so on?

Thanks in advance!

Example:

if ( seconds < 10)
{
  lcd.print("0");
  lcd.print(seconds);
}
if(minutes < 10) 
{
  lcd.print("0");
  lcd.print(minutes);
}
if(hours < 10) 
{
  lcd.print("0");
  lcd.print(hours);
}

You can also use the sprint() function to create a formatted string with all the data in it in one hit, like this

sprintf(aCharArray, "%02d/%02d/%04d", day_variable, month_variable, year_variable)

This is part of standard C libraries and explanation for all the formatting options are readily available thru Mr Google. Note that %f (float) is not supported by the Arduino libraries.

HazardsMind’s approach is used in the RTC library examples for instance, which call the “print2digits” function:

print2digits(tm.Minute);
void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}

(I have nfc why they check it’s > 0… perhaps time goes backwards in some places. Or, the snippet was re-purposed from some other, non time related, sketch.)