如何将由时间、星期和闰秒组成的GPS时间转换为UTC时间戳
how to convert GPS time composed of Time, weeks and leap seconds to UTC Timestamp
我从车辆中集成的 GPS 接收到此数据:
INS_Time::INS_Time_Millisec[ms] # example of the value: 295584830.0
INS_Time::INS_Time_Week[Week] # example of the value: 2077.0
INS_Time::Leap_seconds[s] # example of the value: 18.0
我需要的是 UTC 时间戳,所以我假设我必须将所有来自 GPS 的不同时间组合起来以获得 UTC 时间戳,但我不知道应该如何完成。如果有人能指导我解决这个问题,我将不胜感激。
example of the result I want to have: 1572430625230
我正在使用 python 3.7,如果有一个库,那将非常有帮助,否则我也在寻找一个算法来执行此操作
我的猜测:
根据 https://en.wikipedia.org/wiki/Epoch_(computing)#Notable_epoch_dates_in_computing ,GPS 历元是 1980 年 1 月 6 日,GPS counts weeks (a week is defined to start on Sunday) and 6 January is the first Sunday of 1980
并且根据 http://leapsecond.com/java/gpsclock.htm , GPS time was zero at 0h 6-Jan-1980 and since it is not perturbed by leap seconds GPS is now ahead of UTC by 18 seconds.
所以我们必须定义一个 gps_epoch
并减去给定的闰秒以获得 utc 日期时间
from datetime import datetime, timedelta
import pytz
def gps_datetime(time_week, time_ms, leap_seconds):
gps_epoch = datetime(1980, 1, 6, tzinfo=pytz.utc)
# gps_time - utc_time = leap_seconds
return gps_epoch + timedelta(weeks=time_week, milliseconds=time_ms, seconds=-leap_seconds)
以你为例
>>>gps_datetime(2077, 295584830.0,18.0)
datetime.datetime(2019, 10, 30, 10, 6, 6, 830000, tzinfo=<UTC>)
>>>gps_datetime(2077, 295584830.0,18.0).timestamp()
1572429966.83
但是我和你的预期结果相去甚远(1572430625230
即使是以ms表示)
别忘了pip install pytz
我从车辆中集成的 GPS 接收到此数据:
INS_Time::INS_Time_Millisec[ms] # example of the value: 295584830.0
INS_Time::INS_Time_Week[Week] # example of the value: 2077.0
INS_Time::Leap_seconds[s] # example of the value: 18.0
我需要的是 UTC 时间戳,所以我假设我必须将所有来自 GPS 的不同时间组合起来以获得 UTC 时间戳,但我不知道应该如何完成。如果有人能指导我解决这个问题,我将不胜感激。
example of the result I want to have: 1572430625230
我正在使用 python 3.7,如果有一个库,那将非常有帮助,否则我也在寻找一个算法来执行此操作
我的猜测:
根据 https://en.wikipedia.org/wiki/Epoch_(computing)#Notable_epoch_dates_in_computing ,GPS 历元是 1980 年 1 月 6 日,GPS counts weeks (a week is defined to start on Sunday) and 6 January is the first Sunday of 1980
并且根据 http://leapsecond.com/java/gpsclock.htm , GPS time was zero at 0h 6-Jan-1980 and since it is not perturbed by leap seconds GPS is now ahead of UTC by 18 seconds.
所以我们必须定义一个 gps_epoch
并减去给定的闰秒以获得 utc 日期时间
from datetime import datetime, timedelta
import pytz
def gps_datetime(time_week, time_ms, leap_seconds):
gps_epoch = datetime(1980, 1, 6, tzinfo=pytz.utc)
# gps_time - utc_time = leap_seconds
return gps_epoch + timedelta(weeks=time_week, milliseconds=time_ms, seconds=-leap_seconds)
以你为例
>>>gps_datetime(2077, 295584830.0,18.0)
datetime.datetime(2019, 10, 30, 10, 6, 6, 830000, tzinfo=<UTC>)
>>>gps_datetime(2077, 295584830.0,18.0).timestamp()
1572429966.83
但是我和你的预期结果相去甚远(1572430625230
即使是以ms表示)
别忘了pip install pytz