名前空間
変種
操作

std::chrono::year_month_day_last

From cppreference.com
< cpp‎ | chrono
 
 
 
 
ヘッダー <chrono> で定義
class year_month_day_last;
(C++20以降)

クラスyear_month_day_lastは、特定の年と月の最終日を表します。これはフィールドベースの時間点であり、解像度はstd::chrono::daysですが、月に一度しか最終日を表現できないという制限があります。

std::chrono::yearsstd::chrono::monthsを基にした算術演算が直接サポートされています。std::chrono::sys_daysへの暗黙的な変換により、std::chrono::daysを基にした算術演算を効率的に実行できます。

year_month_day_lastは、TriviallyCopyableかつStandardLayoutTypeです。

目次

[編集] メンバ関数

year_month_day_lastオブジェクトを構築します
(public member function) [編集]
月または年数によって時間点を変更します。
(public member function) [編集]
このオブジェクトのフィールドにアクセスします。
(public member function) [編集]
std::chrono::time_point に変換します。
(public member function) [編集]
このオブジェクトが有効な日付を表すかどうかをチェックします。
(public member function) [編集]

[編集] 非メンバ関数

2つのyear_month_day_last値を比較します
(function) [編集]
year_month_day_last と年または月の数値を加算または減算する
(関数) [edit]
year_month_day_lastをストリームに出力します
(function template) [編集]

[編集] ヘルパークラス

year_month_day_last の書式設定サポート
(クラス テンプレートの特殊化) [edit]
std::chrono::year_month_day_lastのハッシュサポート
(クラステンプレートの特殊化)

[編集]

#include <chrono>
#include <iostream>
 
int main()
{
    const auto ymd = std::chrono::year_month_day
    {
        std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now())
    };
 
    const std::chrono::year_month_day_last ymdl
    {
        ymd.year(), ymd.month() / std::chrono::last
    };
 
    std::cout << "The last day of present month (" << ymdl << ") is: "
              << std::chrono::year_month_day{ymdl}.day() << '\n';
 
    // The 'last' object can be placed wherever it is legal to place a 'day':
    using namespace std::chrono;
    constexpr std::chrono::year_month_day_last
        ymdl1 = 2023y / February / last,
        ymdl2 = last / February / 2023y,
        ymdl3 = February / last / 2023y;
    static_assert(ymdl1 == ymdl2 && ymdl2 == ymdl3);
}

実行結果の例

The last day of present month (2023/Aug/last) is: 31

[編集] 関連項目

特定のyearmonthdayを表す
(クラス) [編集]
English 日本語 中文(简体) 中文(繁體)