#include <RTClib.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
RTC_DS1307 RTC;
LiquidCrystal_I2C lcd(0*27,16,2);
void setup() {
Serial.begin(9600);
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(2022,6,6,6,6,6));
lcd.init();
lcd.backlight();
}
void loop() {
DateTime now = RTC.now();
lcd.setCursor(3,0);
lcd.print(now.year());
lcd.print('-');
lcdData(now.month());
lcd.print('-');
lcdData(now.day());
lcd.setCursor(4,1);
lcdData(now.hour());
lcd.print(':');
lcdData(now.minute());
lcd.print(':');
lcdData(now.second());
}
void lcdData(uint8_t data)
{
if(data<10)
{
lcd.print(0);
lcd.print(data);
}
else{
lcd.print(data);
}
}