- chrono[meta header]
- std[meta namespace]
- class[meta id-type]
- cpp20[meta cpp]
namespace std {
template <class charT>
struct formatter<chrono::weekday, charT>;
}
weekday
クラスに対するstd::formatter
クラステンプレートの特殊化。
フォーマットフラグとしては、以下を使用できる:
フォーマットフラグ | 説明 |
---|---|
%a |
ロケール依存の曜日の略称 |
%A |
ロケール依存の曜日の完全名 |
%u |
10進数での月曜を1とするISO曜日番号 (1-7) |
%Ou |
ロケール依存の%u の異なる表現 |
%w |
10進数での日曜を0とするISO曜日番号 (0-6) |
#include <iostream>
#include <chrono>
#include <format>
namespace chrono = std::chrono;
int main()
{
// デフォルトフォーマットはoperator<<と同じ
std::cout << std::format("{}", chrono::Sunday) << std::endl;
std::cout << std::format("{:%a}", chrono::Sunday) << std::endl; // 略称
std::cout << std::format("{:%A}", chrono::Sunday) << std::endl; // 完全名
// ロケール依存の出力
std::cout << std::format(std::locale("ja_JP.UTF-8"), "{:%a}", chrono::Sunday) << std::endl;
std::cout << std::format(std::locale("ja_JP.UTF-8"), "{:%A}", chrono::Sunday) << std::endl;
}
- std::format[link /reference/chrono/format.md]
- chrono::Sunday[link /reference/chrono/weekday_constants.md]
- std::locale[link /reference/locale/locale.md]
Sun
Sun
Sunday
日
日曜日
- C++20
- Clang: (9.0時点で実装なし)
- GCC: (9.2時点で実装なし)
- Visual C++: (2019 Update 3時点で実装なし)
- chronoの
std::format()
(フォーマットの詳細)