Open joje47 opened 5 years ago
I also had problems with day and month. In my case it seems, that the compiler somehow optimize out the const array monthDays
in Time.cpp
An access to array returns always 0.
After adding the attribute volatile
to this array, output was correct. (tested for Date: 2019-8-1)
I have no clue, why this has happen - maybe dependent on compiler?
Hi, your suggestion worked, but is it safe to use as usual?
Description
Describe your problem. Wrong values for month and year when converting unix timestamp to human readable time.
NTP time is 1546258674 Get: 2018-6-117 12:17:54 Want: 2018-12-31 12:17:54
Steps To Reproduce Problem
Please give detailed instructions needed for anyone to attempt to reproduce the problem.
I get the timestamp correctly from NTP-server (verified using online epoch to human time converter) But when using time_t t = now(); Serial.println(t); Serial.print(year(t)); Serial.print("-"); Serial.print(month(t)); Serial.print("-"); Serial.print(day(t)); Serial.print(" "); Serial.print(hour(t)); printDigits(minute(t)); printDigits(second(t)); Serial.println(); the human readable time gets screwed up. Used the time functions without t variable to, same result.
Hardware & Software
Board Arduino Uno and pro mini (tested both, same result)
Shields / modules used ds3231 rtc esp8266 (esp-01)
Arduino IDE version 1.8.8
Version info & package name (from Tools > Boards > Board Manager) BN: Arduino/Genuino Uno VID: 2341 PID: 0043 SN: 75736303336351310210
Operating system & version Windows 10 latest update Any other software or hardware? No
Arduino Sketch