• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    class
    <chrono>

    std::formatter

    namespace std {
      template <class charT>
      struct formatter<chrono::sys_info, charT>;
    }
    

    概要

    sys_infoクラスに対するstd::formatterクラステンプレートの特殊化。

    フォーマットフラグとしては、以下を使用できる:

    フォーマットフラグ 説明
    %z ISO 8601フォーマットでのUTCからのオフセット (日本だと"+0900")
    %Ez オフセットの時と分の間にコロン (:) が挿入される (日本だと"+09:00")
    %Oz %Ezと等価
    %Z タイムゾーンの略称 (日本だと"JST")

    #include <iostream>
    #include <chrono>
    
    namespace chrono = std::chrono;
    
    int main()
    {
      auto now = chrono::system_clock::now();
    
      // 日本のタイムゾーン
      const chrono::time_zone* tz = chrono::locate_zone("Asia/Tokyo");
      chrono::sys_info si = tz->get_info(now);
    
      // デフォルトフォーマットはoperator<<と同じ (フォーマット未規定)
      std::cout << std::format("{}", si) << std::endl;
    
      std::cout << std::format("{:%z}", si) << std::endl; // オフセット時間
      std::cout << std::format("{:%Z}", si) << std::endl; // タイムゾーンの略称
    }
    

    出力例

    (未検証の行)
    +0900
    JST
    

    バージョン

    言語

    • C++20

    処理系