Hi Guys, i’m saving a file on sdcard with format ddhhmmss and i use these functions to make the name. I use RTCWidget and after syncronize sometimes i get some filenames like “13572324” where 57 can’t be a reazonable hour. Some times i got same thing in the place of the day.
String filename(){
String result = digits(day())+digits(hour())+digits(minute())+digits(second());
Serial.println("filename: "+result);
return result;
}
String digits(int digits){
String result ="";
// utility function for digital clock display: prints preceding colon and leading 0
if(digits < 10)
result = ‘0’+digits;
else
result = digits ;
return result ;
}
Specifically it happens with 8AM and 9AM that i get 56 and 57 respectivelly. From 10AM it works fine.
I see two things it cant be. in funtcion digits the param algo is named digit, may be it can be a trouble y renamed the param to pdigit, and the line :
String result = digits(day())+digits(hour())+digits(minute())+digits(second());
i replaced to:
String dd = digits(day());
String hh = digits(hour());
String mm = digits(minute());
String ss = digits(second()) ;
String result = dd + hh + mm + ss;
I’ll try and i let you know.
Thanks
The time functions work with UNIX time. This is the number of seconds since 1-1-1970. the hour() and so on convert those into readable numbers. So there for it should work fine as you made it. Does it print all right in the Serial monitor if you print it out before saving? That way you can check things. Serial.println() is your friend or debugging
Dear friend, mayby irrelevant to the reported problem but you can format hours, minutes and seconds using this very powerfull ( AFAIK ) command see:
sprintf(currentTime, "%02d:%02d:%02d",hour(), minute(), second());
Thanks and Best Regards,
Mike Kranidis
P.S. The above command is working fine in the ESP8266 series. I don’t know for Arduino etc
Love it. I will try. Thanks