Error with strftime and MbedOS 6


There is a bug with strftime with the Mbed OS 6.

If i run :

char buffer[32];
strftime(buffer, 32, “%FT%H:%M:00.000Z”, localtime(&t));

I get a string with this format

And it should actually return

With the same code and Mbed OS 5, I don’t have this issue.

Any ideas?

I also noticed that my code that ran right some weeks ago, just returns weird results with strftime();
Did not began to dig deeper, so i have no idea why it happens, however increasing the buffer size to 42 solved the issue for me.

I also tried to increase the buffer size but it doesn’t solve the issue for me.

Try this code:
char buffer[42] = {0}; strftime(buffer, 42, "%c", localtime(&t)); if that returns time as expected or even that way are the zeros knocked out. In which case i would also try to force standard printf in mbed_app.json (though i am not sure if that would make a difference)

Also sharing your board can be useful for others to help you.

Same issue with %c, I get 8:54:52 instead of 08:54:52.

Here the code I used to test with a NUCLEO F429ZI

    time_t t = time(NULL);
    char buffer[42] = {0};
    // strftime(buffer, 42, "%FT%H:%M:00.000Z", localtime(&t));
    strftime(buffer, 42, "%c", localtime(&t));
    tr_debug("Time : %s", buffer);

Forcing standard printf won’t solve my problem beaucause I use the time to make a HTTP request and not only for a print.

HI Eddy,

this does indeed look like a possible error. Could you possibly raise an issue in mbed-os on GitHub with as much data as you can provide so that the team can investigate?