- chrono[meta header]
- std[meta namespace]
- class[meta id-type]
- cpp20[meta cpp]
namespace std {
template <class charT>
struct formatter<chrono::month, charT>;
}
month
クラスに対するstd::formatter
クラステンプレートの特殊化。
フォーマットフラグとしては、以下を使用できる:
フォーマットフラグ | 説明 |
---|---|
%b |
ロケール依存の月の略称 |
%B |
ロケール依存の月の完全名 |
%h |
%b と等価 |
%m |
10進数での月。2桁0埋め |
#include <iostream>
#include <chrono>
#include <format>
namespace chrono = std::chrono;
int main()
{
// デフォルトフォーマットはoperator<<と同じ
std::cout << std::format("{}", chrono::April) << std::endl;
std::cout << std::format("{:%b}", chrono::April) << std::endl; // 略称
std::cout << std::format("{:%B}", chrono::April) << std::endl; // 完全名
std::cout << std::format("{:%m}", chrono::April) << std::endl; // 完全名
// ロケール依存の出力
std::cout << std::format(std::locale("ja_JP.UTF-8"), "{:%b}", chrono::April) << std::endl;
std::cout << std::format(std::locale("ja_JP.UTF-8"), "{:%B}", chrono::April) << std::endl;
}
- std::format[link /reference/chrono/format.md]
- chrono::April[link /reference/chrono/month_constants.md]
- std::locale[link /reference/locale/locale.md]
Apr
Apr
April
04
4月
4月
- C++20
- Clang: 9.0 [mark noimpl]
- GCC: 9.2 [mark noimpl]
- Visual C++: 2019 Update 3 [mark noimpl]
- chronoの
std::format()
(フォーマットの詳細)