Datasheet
From now on, you wont have to ever set the time again: the battery will last 5 or more years.
Reading the Time
Now that the RTC is merrily ticking away, we'll want to query it for the time. Lets look at the sketch again to see how
this is done.
There's pretty much only one way to get the time using the RTClib, which is to call now(), a function that returns a
DateTime object that describes the year, month, day, hour, minute and second when you called now().
There are some RTC libraries that instead have you call something like RTC.year() and RTC.hour() to get the current
year and hour. However, there's one problem where if you happen to ask for the minute right at 3:14:59 just before the
next minute rolls over, and then the second right after the minute rolls over (so at 3:15:00) you'll see the time as
3:14:00 which is a minute off. If you did it the other way around you could get 3:15:59 - so one minute off in the other
direction.
void loop () {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
© Adafruit Industries https://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout Page 15 of 22