%02d puts the leading zero in for you. What you need to do is make sure the time is in 24 hour format so that 1 am is 01 and 1 pm is 13. The string will always be the same length.
yes for sure the time is 24 format ... I will try then I'll let you know ...
Thanks,
gnux
Ciao Marco,
so I've did this simple sketch could be a good starting point:
#include <Time.h>
char s[15];
char s1[15];
byte y1,mon1,d1,h1,min1,sec1;
void setup(){
Serial.begin(9600);
setTime(9,25,00,6,2,13);
y1 = 13;
mon1 = 2;
d1 = 6;
h1 = 9;
min1 = 25;
sec1 = 01;
}
void loop(){
time_t t = now();
sprintf(s, "%04d%02d%02d%02d%02d%02d", year(t), month(t), day(t), hour(t), minute(t), second(t));
sprintf(s1, "%04d%02d%02d%02d%02d%02d", (y1+2000), mon1, d1, h1, min1, sec1);
// Debug
Serial.println("Stampo S ");
Serial.println(s);
Serial.println("Stampo S1 ");
Serial.println(s1);
if (strcmp(s,s1) == 0)
{
Serial.println("Condition Verified");
}
delay(1000);
}
so now just to think about the structure how use it ?
do you think that could be fine ?
thanks
gnux
As you are using seconds your comparison will only be true for one second. If your sketch is doing other things it could miss. However to change to one minute resolution just drop seconds from your strings. Then they will be equal within one minute. Drop the minutes for one hour resolution.
If you really need one second resolution then Unix time might be a better solution.