fbiego / ESP32Time

An Arduino library for setting and retrieving internal RTC time on ESP32 boards
MIT License
212 stars 36 forks source link

Month is -1 after setting local time, for what? #19

Closed misisl closed 1 year ago

misisl commented 2 years ago

i see this in code:

void ESP32Time::setTime(int sc, int mn, int hr, int dy, int mt, int yr, int ms) {
   // seconds, minutes, hours, days, months, years $ microseconds(optional)
   // ie setTime(20, 34, 8, 1, 4, 2021) = 8:34:20 1/4/2021
   struct tm t = {0}; // Initialize it to all 0's
   t.tm_year = yr - 1900; // This is year-1900, so 121 = 2021
   t.tm_mon = mt - 1;
   t.tm_mday = dy;
   t.tm_hour = hr;
   t.tm_min = mn;
   t.tm_sec = sc;
   time_t timeSinceEpoch = mktime(&t);
   setTime(timeSinceEpoch, ms);
}

for how reason is t.tm_mon = mt - 1;? If I set the date, I read a date with last month...

fbiego commented 2 years ago

https://www.cplusplus.com/reference/ctime/tm/

tm_mon range is 0 - 11

13