• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <chrono>

    std::chrono::make24

    namespace std::chrono {
      constexpr hours make24(const hours& h, bool is_pm) noexcept;
    }
    

    概要

    12時間ベースの時間を24時間ベースの時間範囲に変換する。

    戻り値

    • is_pmfalseである場合、hが正午以前だと仮定して24時間時計での範囲[0h, 11h]の等価な時間を返す
    • そうでない場合、hを正午以後だと仮定して24時間時計での範囲[12h, 23h]の等価な時間を返す
    • h[1h, 12h]の範囲外である場合、未規定の値を返す

    #include <cassert>
    #include <chrono>
    
    namespace chrono = std::chrono;
    using namespace std::chrono_literals;
    
    int main()
    {
      assert(chrono::make24(3h, false) == 3h);
      assert(chrono::make24(12h, false) == 0h);
    
      assert(chrono::make24(12h, true) == 12h);
      assert(chrono::make24(1h, true) == 13h);
      assert(chrono::make24(3h, true) == 15h);
      assert(chrono::make24(11h, true) == 23h);
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系