I'm using RTClib for my DS3231 module, the problem is the library is displaying the second without zero behind it: 22:1:1 and when i print the time on my 16x2 LCD time is displaying like this:








the second number of seconds is not getting cleared. i know one solution to this is to use lcd.clear() function to update the LCD in each loop but is there any other way to clear that second number or do something so library show zero behind second?

  • What do leap seconds have to do with anything?
    – Majenko
    Commented Jun 20, 2019 at 18:02
  • @Majenko sorry there was a misunderstanding, updated the question. Commented Jun 20, 2019 at 18:06
  • Your problem is that you are printing 1. People don't do that for time. You use 01.
    – Majenko
    Commented Jun 20, 2019 at 18:06
  • how to use "01"? is there a setting i have to change? Commented Jun 20, 2019 at 18:08
  • 2
    If the seconds are less than ten, then print a 0. Then print the seconds. It's that simple. The library has nothing to do with it. It's what you do with the number in your code that matters.
    – Majenko
    Commented Jun 20, 2019 at 18:08

1 Answer 1


It's your responsibility to format the time properly, not the library. The library just gives you a number. If you want a leading zero then it's up to you to provide that leading zero.

For example:

if (now.seconds() < 10) {


char timestr[9];
snprintf(timestr, 9, "%02d:%02d:%02d", now.hours(), now.seconds(), now.minutes());
  • what's snprintf? it's giving me this error: expected constructor, destructor, or type conversion before '(' token Commented Jun 20, 2019 at 18:20
  • 1
    @newbie: It's a very standard libc function. Commented Jun 20, 2019 at 18:25
  • @EdgarBonet i'm sorry but what's the error is about? Commented Jun 20, 2019 at 18:45
  • 1
    Did you use the code inside a function or just dump it into global scope?
    – Majenko
    Commented Jun 20, 2019 at 18:45
  • 1
    Put it in loop() where you want to display the time.
    – Majenko
    Commented Jun 20, 2019 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.