1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include <ESP32Time.h> //ESP32Time rtc; ESP32Time rtc(3600); // offset in seconds GMT+1 void setup() { Serial.begin(115200); rtc.setTime(00, 55, 01, 27, 11, 2021); //ss ,MM,HH , day , month , YYYY // 17th Jan 2021 15:24:30 // all must have two difits for example 2 shouls ve 02 //rtc.setTime(1609459200); // 1st Jan 2021 00:00:00 //rtc.offset = 7200; // change offset value /*---------set with NTP---------------*/ // configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); // struct tm timeinfo; // if (getLocalTime(&timeinfo)){ // rtc.setTimeStruct(timeinfo); // } } void loop() { // Serial.println(rtc.getTime()); // (String) 15:24:38 // Serial.println(rtc.getDate()); // (String) Sun, Jan 17 2021 // Serial.println(rtc.getDate(true)); // (String) Sunday, January 17 2021 // Serial.println(rtc.getDateTime()); // (String) Sun, Jan 17 2021 15:24:38 // Serial.println(rtc.getDateTime(true)); // (String) Sunday, January 17 2021 15:24:38 // Serial.println(rtc.getTimeDate()); // (String) 15:24:38 Sun, Jan 17 2021 // Serial.println(rtc.getTimeDate(true)); // (String) 15:24:38 Sunday, January 17 2021 // // Serial.println(rtc.getMicros()); // (long) 723546 // Serial.println(rtc.getMillis()); // (long) 723 // Serial.println(rtc.getEpoch()); // (long) 1609459200 // Serial.println(rtc.getSecond()); // (int) 38 (0-59) // Serial.println(rtc.getMinute()); // (int) 24 (0-59) // Serial.println(rtc.getHour()); // (int) 3 (0-12) // Serial.println(rtc.getHour(true)); // (int) 15 (0-23) // Serial.println(rtc.getAmPm()); // (String) pm // Serial.println(rtc.getAmPm(true)); // (String) PM // Serial.println(rtc.getDay()); // (int) 17 (1-31) // Serial.println(rtc.getDayofWeek()); // (int) 0 (0-6) // Serial.println(rtc.getDayofYear()); // (int) 16 (0-365) // Serial.println(rtc.getMonth()); // (int) 0 (0-11) // Serial.println(rtc.getYear()); // (int) 2021 // Serial.println(rtc.getLocalEpoch()); // (long) 1609459200 epoch without offset Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S")); // (String) returns time with specified format // formating options http://www.cplusplus.com/reference/ctime/strftime/ struct tm timeinfo = rtc.getTimeStruct(); //Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); // (tm struct) Sunday, January 17 2021 07:24:38 delay(1000); } |
esp32 rtc clock