On ESP32 I need to convert a date and time in the form "10/23/2023 11:37:15 AM" to a 24 hour format in the form "23/10/2023 11:37:15". I use strptime function, but it completely ignores the AM/PM flag and returns the time as if the source time contained PM.
Example:
Code: Select all
#include <time.h>
struct tm ts;
char output[100];
void setup() {
Serial.begin(115200);
delay(1000);
char input[] = "10/23/2023 11:37:15 AM";
Serial.printf("Input is '%s'\n", input);
strptime(input, "%m/%d/%Y %I:%M:%S %p", &ts);
//strptime(input, "%m/%d/%Y %r", &ts); // the same problem
// test result
strftime(output, sizeof(output), "%d/%m/%Y %H:%M:%S", &ts);
Serial.printf("Output is '%s'\n", output);
}
void loop() {
}