I believe that the following code is safe to return the string, even though inelegant, and works as expected, but I'd like confirmation of that, and I'd also like a test case to wrap around it that proves it is safe; ie that the contents of the string are available to the caller via .c_str() method, after the stack is re-used: ie, how can I force the stack on which the local variable resides to be freed/re-used (I'm using Visual Studio 2019 and PVS-Studio static code analysis, neither of which generates a warning). I don't like replacing the local szLocalTime with a global, nor do I like the idea of a malloc in the function as that places the onus on the caller to free. I've added some examples of cases that fill in the char[], eg C lib or Win32 functions that don't know about strings.
string FormatTimestamp(SYSTEMTIME st)
{
    char szLocalTime[1000];
    szLocalTime[0] = 0;
    // *** Some code that depends on a char buffer fills szLocalTime...
    // eg. strftime(szLocalTime, sizeof(szLocalTime)...);
    // eg. GetDlgItemText(hDlg, ID, szLocalTime, sizeof(szLocalTime));
    string s = szLocalTime; // <-- the question relates to this
    return s;
}
 
     
    