wcsftime
在标头
<wchar.h> 定义
|
||
(C95 起) | ||
将来自给定的日历时间 time
的日期和时间信息,按照格式字符串 format
,转换成空终止宽字符串 str
。最多写入 count
个宽字符。
参数
str | - | 指向待输出的 wchar_t 数组首元素的指针
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
count | - | 最大写入宽字符数 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
format | - | 指向指定转换格式的空终止宽字符串指针。
格式字符串由零或更多个说明符和通常字符(除
|
返回值
成功时,返回写入 str
所指向的宽字符数组的字符数,不包含终止 L'\0' 。若在能存储整个字符串前抵达 count
,则返回 0 ,写入内容是未定义的。
示例
#include <stdio.h> #include <time.h> #include <wchar.h> #include <locale.h> int main(void) { wchar_t buff[40]; struct tm my_time = { .tm_year=112, // = 2012 年 .tm_mon=9, // = 10 月 .tm_mday=9, // = 9 日 .tm_hour=8, // = 8 时 .tm_min=10, // = 10 分 .tm_sec=20 // = 20 秒 }; if (wcsftime(buff, sizeof buff, L"%A %c", &my_time)) { printf("%ls\n", buff); } else { puts("wcsftime failed"); } setlocale(LC_ALL, "ja_JP.utf8"); if (wcsftime(buff, sizeof buff, L"%A %c", &my_time)) { printf("%ls\n", buff); } else { puts("wcsftime failed"); } }
输出:
Sunday Sun Oct 9 08:10:20 2012 日曜日 2012年10月09日 08時10分20秒
引用
- C11 标准(ISO/IEC 9899:2011):
-
- 7.29.5.1 The wcsftime function (第 439-440 页)
- C99 标准(ISO/IEC 9899:1999):
-
- 7.24.5.1 The wcsftime function (第 385-386 页)
参阅
将 struct tm 对象转换成自定义文本表示 (函数) |