#C 语言标准库函数 wcsftime
#include <wchar.h>
size_t wcsftime(wchar_t *restrict s, size_t maxsize,
const wchar_t *restrict format, const struct tm *restrict timeptr);
说明
按照格式串和当前 LC_TIME 将分解时间转换为宽字符串。支持日期、时间、星期等占位符。
格式所用的时间字段必须有效。例如使用星期指令时,应先让 mktime 或其他时间转换函数填好 tm_wday。
自 C95 起提供。
参数
s- 接收结果的宽字符数组。maxsize- 目标 wchar_t 元素容量,包含末尾的空宽字符。format- 宽字符格式串,例如 L"%Y-%m-%d"。timeptr- 指向已填充的分解时间。
返回值
- 容纳完整字符串时返回写入的宽字符数,排除终止符。空间不足时返回零,目标内容未指定。
#示例
#include <wchar.h>
#include <time.h>
int main(void)
{
struct tm day = {.tm_year = 124, .tm_mon = 1, .tm_mday = 29};
wchar_t text[32];
size_t length = wcsftime(text, 32, L"%Y-%m-%d", &day);
return length != 10 || wcscmp(text, L"2024-02-29") != 0;
}
#相关接口
- 接口变体 strftime