Hello,
I'm trying to build a method that should be return the current date and time as formatted string and for some reason the returned value is not being formatted correctly.
This is the method which pretty is similar to the example of the SimpleTime.ino, but instead of printing I'm trying to return the value as string as mentioned above:
String getCurrTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("No time available (yet)");
time_set_flg = false;
return "No time available (yet)";
}
char timeStringBuff[25];
strftime( timeStringBuff,
sizeof(timeStringBuff),
"%Y/%m/%d %H:%M:%S %Z",
&timeinfo);
// return timeStringBuff;
// return String( timeStringBuff );
String buffer( timeStringBuff );
Serial.printf( "timeStringBuff: %s buffer: %s\n",
timeStringBuff,
buffer );
return buffer;
}
I commented out the attempt of returns from the formatted variable timeStringBuff and tried converting the result to a buffer variable to print the value, this is the output:
timeStringBuff: 2023/07/29 21:22:00 CDT buffer: �T�?
Any idea why the char buffer timeStringBuff cannot be returned or converted as String?, any help would be greatly appreciated.
Thank you