esp32 rtc
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
LiquidCrystal_I2C lcd(0x27, 16, 2);
RTC_DS1307 rtc;
int day;
int month;
int year;
int hour;
int minute;
int second;
void setup() {
rtc.begin();
lcd.init();
lcd.backlight();
} ////////////////////end loop
void loop() {
DateTime now = rtc.now();
day = now.day();
month = now.month();
year = now.year();
hour = now.hour();
minute = now.minute();
second = now.second();
//////////////////////////////date
lcd.setCursor(0, 0);
lcd.print("Date");
lcd.setCursor(6, 0);
if (day <= 9) {
lcd.print("0");
}
lcd.print(day);
lcd.setCursor(8, 0);
lcd.print("/");
lcd.setCursor(9, 0);
if (month <= 9) {
lcd.print("0");
}
lcd.print(month);
lcd.setCursor(11, 0);
lcd.print("/");
lcd.setCursor(12, 0);
lcd.print(year);
lcd.setCursor(0, 1);
//////////////////////////////time
lcd.print("Time");
lcd.setCursor(6, 1);
if (hour <= 9){ ////////////h
lcd.print("0");
}
lcd.print(hour);
lcd.setCursor(8, 1);
lcd.print(":");
lcd.setCursor(9, 1);
if (minute <= 9) { /////////////m
lcd.print("0");
}
lcd.print(minute);
lcd.setCursor(11, 1);
lcd.print(":");
lcd.setCursor(12, 1);
if (second <= 9) { //////////////s
lcd.print("0");
}
lcd.print(second);
} ////////////////////end loop