LlmFormatTimestamp Function  
 
BOOL INT LlmFormatTimestamp(
  TIME_T tTimestamp,  
  LPTSTR lpszDateTime,  
  INT nMaxLength,  
  BOOL bLocalTime  
);

The LlmFormatTimestamp function converts a timestamp value to an ISO 8601 formatted date and time string.

Parameters

tTimestamp
A 64-bit timestamp value associated with a message or response. This value represents the number of seconds that have elapsed since January 1, 1970 UTC.
lpszDateTime
A pointer to a buffer that receives the formatted date and time string. This parameter cannot be NULL and must be large enough to store the entire string, including the terminating null character.
nMaxLength
The size of the buffer specified by the lpszDateTime parameter, in characters. This value must be large enough to store the formatted string. A buffer of at least 32 characters is recommended.
bLocalTime
If this parameter is non-zero, the timestamp is converted to the local system time before formatting. If this parameter is zero, the timestamp is formatted as Coordinated Universal Time (UTC).

Return Value

If the function succeeds, the return value is the number of characters copied into the string buffer. If the function fails, the return value is zero. To get extended error information, call LlmGetLastError.

Remarks

The LlmFormatTimestamp function converts a timestamp value returned by the library into a human-readable date and time string using the ISO 8601 format. This format is consistent, unambiguous, and suitable for logging, display, or storage.

The tTimestamp parameter is a standard 64-bit Unix time value and can be used interchangeably with functions in the C standard library such as gmtime or localtime. Because it is a 64-bit integer, it is not impacted by the Year 2038 problem. Timestamps are returned by functions such as LlmSendMessage and can be converted into a local date and time using the LlmConvertTimestamp function.

The formatted string is returned in the form "YYYY-MM-DDThh:mm:ssZ" when UTC is specified. When local time is specified, the string is returned in the form "YYYY-MM-DDThh:mm:ss+hh:mm" or "YYYY-MM-DDThh:mm:ss-hh:mm", depending on the current time zone offset.

When bLocalTime is non-zero, the formatted string includes the local time zone offset. This ensures that the resulting value is not ambiguous and preserves the ISO 8601 format.

Applications that require locale-specific formatting or alternative date and time representations should convert the timestamp using LlmConvertTimestamp and apply additional formatting as needed. If you need to display the date and time using conventions for the current locale, use functions such as GetDateFormatEx and GetTimeFormatEx in the Windows API.

Example

// Enumerate the message history and display message details
LLM_MESSAGE clientMessage = { sizeof(LLM_MESSAGE), 0 };
LLM_RESPONSE serverResponse = { sizeof(LLM_RESPONSE), 0 };

if (LlmGetFirstMessage(hClient, 0, &clientMessage, &serverResponse))
{
    do
    {
        TCHAR szDateTime[64] = {0};

        LlmFormatTimestamp(clientMessage.tTimestamp, szDateTime, _countof(szDateTime), FALSE);

        _tprintf(_T("\nMessage %u\n"), clientMessage.dwMessageId);
        _tprintf(_T("  Timestamp:       %s\n"), szDateTime);
        _tprintf(_T("  Input Tokens:    %u\n"), clientMessage.nInputTokens);
        _tprintf(_T("  Content Length:  %u\n"), clientMessage.nContentLength);
        _tprintf(_T("  Content:         \"%s\"\n"), clientMessage.lpszContent);

        LlmFormatTimestamp(serverResponse.tTimestamp, szDateTime, _countof(szDateTime), FALSE);

        _tprintf(_T("\nResponse %u\n"), serverResponse.dwMessageId);
        _tprintf(_T("  Timestamp:       %s\n"), szDateTime);
        _tprintf(_T("  Elapsed:         %u ms\n"), serverResponse.dwElapsed);
        _tprintf(_T("  Output Tokens:   %u\n"), serverResponse.nOutputTokens);
        _tprintf(_T("  Content Length:  %u\n"), serverResponse.nContentLength);
        _tprintf(_T("  Content:         \"%s\"\n"), serverResponse.lpszContent);
        _tprintf(_T("  Response ID:     %s\n"), (serverResponse.lpszResponseId ? serverResponse.lpszResponseId : _T("None")));
        _tprintf(_T("  Model Name:      %s\n"), (serverResponse.lpszModelName ? serverResponse.lpszModelName : _T("None")));
        _tprintf(_T("  Status Text:     %s\n"), (serverResponse.lpszStatusText ? serverResponse.lpszStatusText : _T("None")));
    }
    while (LlmGetNextMessage(hClient, &clientMessage, &serverResponse));
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

LlmConvertTimestamp, LlmGetFirstMessage, LlmGetNextMessage, LLM_MESSAGE, LLM_RESPONSE