// https://forum.arduino.cc/t/time-isnt-converted-correct-from-unix-time/1060600/3
#include <time.h>
int32_t modifyEpoch()
{
uint32_t epoch = 0;
time_t rawtime = epoch;
struct tm ts = *localtime(&rawtime);
char buf[8]{""};
int32_t offset = 0;
strftime(buf, sizeof(buf), "%Y", &ts); // get year of 0
Serial.println(buf);
if (atoi(buf) == 2000 )
{
offset = -946684800;
Serial.println(F("force offset"));
}
else if (atoi(buf) != 1970 )
{
Serial.print (F("adopt function to handle epoch Start ")); Serial.println(buf);
}
return offset;
}
int32_t epochOffset = 0;
void setup() {
Serial.begin(115200);
epochOffset = modifyEpoch(); // call once
uint32_t epoch = 1669978215; //Fri Dec 02 2022 10:50:15 GMT+0000
epoch += epochOffset;
char buf[80];
time_t rawtime = epoch; // time(epoch);
struct tm ts = *localtime(&rawtime);
strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
Serial.println(buf);
}
void loop() {
// put your main code here, to run repeatedly:
}