- chrono[meta header]
- std[meta namespace]
- class[meta id-type]
- cpp20[meta cpp]
namespace std {
template <class charT>
struct formatter<chrono::year_month, charT>;
}year_month_dayクラスに対するstd::formatterクラステンプレートの特殊化。
monthとyearで利用可能なフォーマットフラグを使用できる。
#include <iostream>
#include <chrono>
#include <format>
namespace chrono = std::chrono;
using namespace std::chrono_literals;
int main() {
chrono::year_month date = 2020y/3;
// デフォルトフォーマットはoperator<<と同じ
std::cout << std::format("1 : {}", date) << std::endl;
std::cout << std::format("2 : {:%Y/%b}", date) << std::endl;
std::cout << std::format("3 : {:%Y年%m月}", date) << std::endl;
}- std::format[link /reference/chrono/format.md]
- 2020y[link /reference/chrono/year/op_y.md]
1 : 2020/Mar
2 : 2020/Mar
3 : 2020年03月
- C++20
- Clang: (9.0時点で実装なし)
- GCC: (9.2時点で実装なし)
- Visual C++: (2019 Update 3時点で実装なし)
- chronoの
std::format()(フォーマットの詳細)