wcsftime -- Convert to Formatted Date and Time

Format

#include <wchar.h>
size_t wcsftime(wchar_t *wdest, size_t maxsize,
                const wchar_t *format, const struct tm *timeptr);

Language Level: ANSI 93, XPG4
wcsftime converts the time and date specification in the timeptr structure into a wide-character string. It then stores the null-terminated string in the array pointed to by wdest according to the format string pointed to by format. maxsize specifies the maximum number of wide characters that can be copied into the array.

wcsftime works just like strftime, except that it uses wide characters.

The format string is a multibyte character string containing:

The characters that are converted are determined by the LC_TIME category of the current locale and by the values in the time structure pointed to by timeptr. The time structure pointed to by timeptr is usually obtained by calling the gmtime or localtime function.

For details on the conversion specifiers you can use in the format string, see strftime -- Convert to Formatted Time.

Return Value
If the total number of wide characters in the resulting string, including the terminating null wide character, does not exceed maxsize, wcsftime returns the number of wide characters placed into wdest, not including the terminating null wide character. Otherwise, wcsftime returns 0 and the contents of the array are indeterminate.

Example
This example obtains the date and time using localtime, formats the information with wcsftime, and prints the date and time.

#include <stdio.h>
#include <time.h>
#include <wchar.h>
int main(void)
{
   struct tm *timeptr;
   wchar_t   dest[100];
   time_t    temp;
   size_t    rc;
   temp = time(NULL);
   timeptr = localtime(&temp);
   rc = wcsftime(dest, sizeof(dest)-1, L" Today is %A,"
                 L" %b %d.\n Time: %I:%M %p", timeptr);
   printf("%d characters placed in string to make:\n\n%ls\n", rc, dest);
   return 0;
   /********************************************************************
      The output should be similar to:
      43 characters placed in string to make:
       Today is Thursday, Nov 10.
       Time: 04:56 PM
   ********************************************************************/
}



gmtime -- Convert Time
localtime -- Convert Time
strftime -- Convert to Formatted Time
strptime -- Convert to Formatted Date and Time
<wchar.h>