When I was writing a time related system I found a bug.
I set a specific time in struct tm and converted it time_t.
But the result is not same to www.unixtimestamp.com value.
Here is my code and please check it.
Environment
HW: Arduino Uno R3
IDE: 1.8.1
#include <time.h>
struct tm stm1, *stm2, *stm3;
time_t tt1, tt2, tt3;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while(!Serial)
;
// 05/15/2017 @ 5:30pm (UTC) is 1494869420 (check it www.unixtimestamp.com)
stm1.tm_sec = 20;
stm1.tm_min = 30;
stm1.tm_hour = 17;
stm1.tm_mday = 15;
stm1.tm_mon = 4;
stm1.tm_year = 117;
stm1.tm_wday = 1;
stm1.tm_yday = 134;
stm1.tm_isdst = 0;
tt1 = mktime(&stm1);
Serial.println(" After input the struct tm manually:");
Serial.println(asctime(&stm1));
Serial.println(tt1);
stm2 = gmtime(&tt1);
tt2 = mktime(stm2);
Serial.println(" After gmtime() and mktime()");
Serial.println(asctime(stm2));
Serial.println(tt2);
tt3 = 1494956208;
stm3 = gmtime(&tt3);
tt3 = mktime(stm3);
Serial.println(" After gmtime() and mktime() using time_t value from the www.unixtimestamp.com:");
Serial.println(asctime(stm3));
Serial.println(tt3);
}
void loop() {
// put your main code here, to run repeatedly:
}