命名空间
变体
操作

std::time_put

来自 cppreference.cn
< cpp‎ | locale
 
 
 
 
 
定义于头文件 <locale>
template<

    class CharT,
    class OutputIt = std::ostreambuf_iterator<CharT>

> class time_put;

类模板 std::time_put 封装日期和时间格式化规则。I/O 操作符 std::put_time 使用 I/O 流区域设置的 std::time_put facet 生成 std::tm 对象的文本表示。

cpp/locale/time basecpp/locale/locale/facetstd-time put-inheritance.svg

继承图

如果标准库不保证提供 std::time_put 特化(见下文),则其 put()do_put() 的行为将不保证按指定进行。

目录

[编辑] 特化

标准库保证提供以下特化(它们 要求由任何区域设置对象实现

定义于头文件 <locale>
std::time_put<char> 创建日期和时间的窄字符串表示
std::time_put<wchar_t> 创建日期和时间的宽字符串表示

此外,标准库还保证提供满足以下类型要求的每个特化:

[编辑] 嵌套类型

类型 定义
char_type CharT
iter_type OutputIt

[编辑] 数据成员

成员 描述
std::locale::id id [static] facet 的标识符

[编辑] 成员函数

构造新的 time_put facet
(public 成员函数) [编辑]
析构 time_put facet
(protected 成员函数) [编辑]
调用 do_put
(public 成员函数) [编辑]

[编辑] 受保护的成员函数

[virtual]
格式化日期/时间并写入输出流
(virtual protected 成员函数) [编辑]

[编辑] 示例

#include <codecvt>
#include <ctime>
#include <iomanip>
#include <iostream>
 
int main()
{
    std::time_t t = std::time(nullptr);
    std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(std::cout.rdbuf());
    std::wostream out(&conv);
    out.imbue(std::locale("ja_JP.utf8"));
 
    // this I/O manipulator std::put_time uses std::time_put<wchar_t>
    out << std::put_time(std::localtime(&t), L"%A %c") << '\n';
}

输出

水曜日 2011年11月09日 12時32分05秒

[编辑] 另请参阅

表示命名区域设置的系统提供的 std::time_put
(类模板) [编辑]
从输入字符序列解析时间/日期值到 std::tm
(类模板) [编辑]
(C++11)
根据指定格式格式化并输出日期/时间值
(函数模板) [编辑]