ESP32Time icon indicating copy to clipboard operation
ESP32Time copied to clipboard

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

Open misisl opened this issue 3 years ago • 1 comments

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...

misisl avatar Sep 06 '22 10:09 misisl

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

tm_mon range is 0 - 11

#13

fbiego avatar Sep 07 '22 07:09 fbiego