Name

wcsftime

Synopsis

Generates a formatted wide string of time and date information

#include <time.h>
#include <wchar.h>
size_twcsftime( wchar_t * restrict s, size_t n,
                 const wchar_t * restrict format,
                 const struct tm * restrict timeptr );

The wcsftime() function is similar to strftime(), except that its format string argument and the output string it generates are wide character strings. Accordingly, the length n and the function’s return value indicate numbers of wide characters, not byte characters. The locations that wcsftime() reads from and writes to using its restricted pointer parameters must not overlap.

Example

#define MAX_HDR 1024

time_t now;
struct tm *localnow;
wchar_t hdr_date[MAX_HDR] = L"";

time( &now );
localnow = localtime( &now );

if (wcsftime( hdr_date, MAX_HDR, L"Date: %a, %d %b %Y %T %z", localnow ) )
  fputws( hdr_date, stdout );
else
  return -1;

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.