template <class Duration>
static gps_time<common_type_t<Duration, seconds>>
from_utc(const utc_time<Duration>&) noexcept;
概要
UTC時間からGPS時間に変換する。
戻り値
return gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s;
ここで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;
}
22
#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;
出力
2019-10-24
2019-10-24 00:00:00 UTC
2019-10-24 00:00:18 GPS
27
バージョン
言語
- C++20
処理系
- Clang: 9.0 ❌
- GCC: 9.2 ❌, 13.1 ✅
- Visual C++: 2019 Update 3 ❌