I am calling the printLocalTime() function to retrieve the month and day as part
of timestamping the last time a pressure pump ran.
The day value is correct but not the month value. Instead of getting a numeric 2 for
the month of February there is a 1. Am I misunderstanding something about how this
value is presented?
void printLocalTime() { // this function monitors current time of day to initiate
// pump counter reset at midnight
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
time_hour = timeinfo.tm_hour; // tm structure element "hour" from time.h
time_min = timeinfo.tm_min; // "minute" " "
time_sec = timeinfo.tm_sec; // "second"
time_month = timeinfo.tm_mon;
time_day = timeinfo.tm_mday;
if (time_hour == hour_trigger && time_min == min_trigger && time_sec == sec_trigger) {
Serial.println("Reset counters...");
counter_reset = true;
delay(3000); // used to avoid conflict as time rolls over to new day
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S zone %Z %z ");
Serial.println();
Serial.println("Month [timeinfo.tm_mon] is: ");
Serial.println(timeinfo.tm_mon);
Serial.println();
}
This the serial monitor output where displaying the entire date/time/time zone
and just the value of the timeinfo.tm_mon:
Tuesday, February 27 2024 14:30:18 zone CST -0600
Month [timeinfo.tm_mon] is:
1
Tuesday, February 27 2024 14:30:18 zone CST -0600
Month [timeinfo.tm_mon] is:
1