You need the function strftime for this. cplusplus.com/reference/ctime/strftime Try replacing the "loop" function with this one: void loop() { char hourMin[6]; getLocalTime(&tInfo); // sntp sync at startup & every 4 hours from then on display.clearDisplay(); display.drawRect(0, 0, 128, 40, 1); display.setFont(&FreeSansBold18pt7b); display.setCursor(4, 31); strftime(hourMin, sizeof(hourMin), "%I:%M", &tInfo); display.printf(hourMin); display.setFont(&FreeSansBold12pt7b); display.printf(":%02d", tInfo.tm_sec); display.setCursor(4, 63); display.printf("%02d-%02d-%04d", tInfo.tm_mday, 1 + tInfo.tm_mon, 1900 + tInfo.tm_year); display.display(); }
Köszönöm szépen! thank you very much!
Perfect, It works .. How can I change it to 12 hour format? Thanks
You need the function strftime for this.
cplusplus.com/reference/ctime/strftime
Try replacing the "loop" function with this one:
void loop() {
char hourMin[6];
getLocalTime(&tInfo); // sntp sync at startup & every 4 hours from then on
display.clearDisplay();
display.drawRect(0, 0, 128, 40, 1);
display.setFont(&FreeSansBold18pt7b);
display.setCursor(4, 31);
strftime(hourMin, sizeof(hourMin), "%I:%M", &tInfo);
display.printf(hourMin);
display.setFont(&FreeSansBold12pt7b);
display.printf(":%02d", tInfo.tm_sec);
display.setCursor(4, 63);
display.printf("%02d-%02d-%04d", tInfo.tm_mday, 1 + tInfo.tm_mon, 1900 + tInfo.tm_year);
display.display();
}