I am using rtc widget which prints the date on terminal. The format that appears on the terminal is DD / MM / YYYY and I would like to have only YY appear at the end of the date. Is there a trick to do it?
Thanks a lot
Is this done via a sketch running on a device, or via Eventor?
If it’s via a sketch then post your code (correctly formatted with triple backticks of course).
Pete.
void orario(){ // Calcola orario e data corrente
if(go==0){// se è il primo avvio
go=1;
terminal.clear();
setSyncInterval(1); // sincronizzazione al primo avvio
currentDate = String(day()) + "/" + month() + "/" + year(); // giorno/mese/anno
currentTime = String(hour()) + ":" + minute() + ":" + second(); // ora:minuti:secondi
terminal.print(currentDate); terminal.print("-"); terminal.print(currentTime); terminal.println(" Start");
setSyncInterval(60 * 60); // Intervallo di sincronizzazione dati (10 minuti)
terminal.flush();
}
currentDate = "";
currentTime = "";
currentDate = String(day()) + "/" + month() + "/" + year(); // giorno/mese/anno
currentTime = String(hour()) + ":" + minute() + ":" + second(); // ora:minuti:secondi
}
this is a part of the code that writes the date as well as the time
I suppose using substring(2) on a string of the year will return the last two characters.
Or, a slightly dirtier way is to subtract 2000 from the year, which will continue to return the correct result for the next 79 and a bit years.
Pete.
Pete.
Oh my God. Sometimes you think that the solution is much more complicated … The “dirty” one works very well Thanks !!
1 Like