I am struggling with converting between a time structure tm and time_t variable. I've been through a bunch of posts but haven't yet figured out what I am doing wrong.
The following code running on ESP32 produces the following response:
base_time date: 11-12-2024 13:14:15
new_time date: 7-8-2019 18:38:31
Why the difference?
#include "TimeLib.h"
void setup() {
Serial.begin(9600);
delay(500);
Serial.println();
time_t new_time;
tm base_time = {0};
char temp_ch[80];
base_time.tm_year = 2024;
base_time.tm_mon = 11;
base_time.tm_mday = 12;
base_time.tm_hour = 13;
base_time.tm_min = 14;
base_time.tm_sec = 15;
base_time.tm_isdst = -1;
new_time = mktime(&base_time);
sprintf(temp_ch, "base_time date: %d-%d-%d %d:%d:%d", base_time.tm_mon, base_time.tm_mday, base_time.tm_year, base_time.tm_hour, base_time.tm_min, base_time.tm_sec);
Serial.println(temp_ch);
sprintf(temp_ch, " new_time date: %d-%d-%d %d:%d:%d", month(new_time), day(new_time), year(new_time), hour(new_time), minute(new_time), second(new_time));
Serial.println(temp_ch);
}
void loop() {
}