In C, wcsftime() formats date and time as a wide string. It belongs to the wide-character tools declared in <wchar.h>.
Use wchar_t for wide characters and prefix wide literals with L, as in L"Hello". The examples below use simple C Programming Tutorial patterns and print wide strings with %ls.
Syntax
The following concrete call shows the argument shape before the formal declaration.
C
wcsftime(out, 40, L"%Y-%m-%d", &timeinfo);
Call
What it does
wcsftime(out, 40, L"%Y-%m-%d", &timeinfo)
Formats date and time as a wide string in a typical call.
Include <wchar.h>. Add only the supporting headers actually used by your program.
Prepare a practical variation. The data is arranged specifically to check buffer capacity.
Apply the wide-string operation.wcsftime(out, 40, L"%Y-%m-%d", &timeinfo) works in wchar_t elements and respects the ending L'\0'.
Notice the safety rule. The example keeps the count, destination capacity, stream state, and terminator requirements visible.
Interpret the output.2026-11-17 confirms the behavior demonstrated by this example.
Frequently Asked Questions
wcsftime() formats date and time as a wide string. It is part of the standard wide-character library.
Its parameters are ws, maxsize, format, timeptr. ws: A wide-string buffer, source string, or format string. maxsize: Capacity of the destination wide-string buffer. format: A wide format string that controls printing or scanning. timeptr: Pointer to the broken-down calendar time to format.
size_t count means the number of wide characters produced or required; zero can mean the output did not fit.
Include <wchar.h> for wcsftime(). Include only the supporting headers used by your program, such as <stdio.h> for FILE or <stdarg.h> for va_list.
Inputs must be valid null-terminated wide strings unless the API explicitly uses a count. Writable destinations need room for the result and L'\0'.