What time is it? (ESP32 time)

I read the clock from NTP and then ESP32 uses it, see the code:

void printLocalTime()
{
  time(&now);
  localtime_r(&now, &myTimeInfo);
  strftime(NTPdatum, sizeof(NTPdatum), "%H:%M:%S %d.%m.%Y", &myTimeInfo);
}

But I would like to do a function where in the month 4 to 9 in the time 4 to 21 hours the function returns false to me, otherwise true.
How can I achieve this?

Please post a complete sketch rather than just a snippet

Where are you stuck ?

The first step is to look up what fields are in 'myTimeInfo'. I expect you will get a month and an hour.

boolean function()
{
  time(&now);
  localtime_r(&now, &myTimeInfo);
  return !(myTimeInfo.month >= 4 && myTimeInfo.month <= 9 && 
    myTimeInfo.hour >= 4 && myTimeInfo.hour <= 21);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.