Instable RTClib?

For a while this code was stable:

#include <RTClib.h>
RTC_DS1307 rtc;
DateTime epoch;
char timeinfo[80];
epoch = rtc.now();
sprintf(timeinfo,"%d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d ",epoch.year(),epoch.month(),epoch.day(),epoch.hour(),epoch.minute(),epoch.second());
Serial.println(timeinfo);

But recently it became instable, it now appears to be stable again when I do this:

{
epoch = rtc.now();
int yy,mm,dd,hhh,mmm,sss;
yy = epoch.year();
mm = epoch.month();
dd = epoch.day();
hhh = epoch.hour();
mmm = epoch.minute();
sss = epoch.second();
sprintf(timeinfo,"%d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",yy,mm,dd,hhh,mmm,sss);
}

Serial.println(timeinfo);

Why do rtc calls suddenly return garbage that I can’t print with %d? What’s up?

But recently it became instable

Unstable how?

problem resolved, there is nothing wrong with rtclib or sprintf, the problem was somewhere else in the code.

PaulS:

But recently it became instable

Unstable how?

like printing garbage, but it was coming from a corrupted character string, problem is resolved