• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <chrono>

    std::chrono::gps_clock::from_utc

    template <class Duration>
    static gps_time<common_type_t<Duration, seconds>>
      from_utc(const utc_time<Duration>&) noexcept;
    

    概要

    UTC時間からGPS時間に変換する。

    戻り値

    ここで315964809は、システム時間のエポック1970年1月1日とGPS時間のエポック1980年1月6日 (この年の最初の日曜日) との差である秒数に、その間に挿入されたうるう秒である9秒を加算した秒数である。

    #include <iostream>
    #include <chrono>
    
    namespace chrono = std::chrono;
    using namespace std::chrono_literals;
    
    int main()
    {
      // ここでは日単位のシステム時間を、秒単位のUTC時間とGPS時間に変換している。
      auto st = chrono::sys_days{2019y/10/24};    // システム時間,日単位
      auto ut = chrono::utc_clock::from_sys(st);  // UTC時間,秒単位
      auto tt = chrono::gps_clock::from_utc(ut);  // GPS時間,秒単位
    
      // UTC時間のうるう秒に関する情報
      chrono::leap_second_info info = chrono::get_leap_second_info(ut);
    
      std::cout << st << std::endl;
      std::cout << ut << " UTC" << std::endl;
      std::cout << tt << " GPS" << std::endl;
      std::cout << info.elapsed.count() << std::endl;
    }
    

    出力

    2019-10-24
    2019-10-24 00:00:00 UTC
    2019-10-24 00:00:18 GPS
    27
    

    バージョン

    言語

    • C++20

    処理系