gps周 python_基于Python的UTC时间到GPS时间转换器

只需从UNIX时间中减去315964782。

GPS时间从1980年1月5日开始。UNIX时间从1970年1月1日开始。它们只是有不同的起点,或者Epochs。这两个时期之间的区别在于这两个日期之间的秒数加上18 GPS闰秒(目前为止)。

正如其他人所指出的,GPS leap seconds是随着地球自转逐渐减慢而周期性增加的。we must update our source code manually for each time the leap second occurs (ex. next 2018, 2019,...)? Is there any feasible way to prevent this problem?

许多设备都有一条信息,指示“当前”有效的GPS秒数。我的C++ NeoGPS库有一个example program,它请求从UBLUX设备(二进制消息定义的{a5})中获取当前的GPS秒数。有关NAV-TIMEGPS信息的更多信息,请参阅ublox NEO xx规范。

其他制造商可能有自己的协议和消息来获取当前的GPS闰秒。

但是:

大多数GPS设备以UTC为单位报告时间,其中已包括闰秒。除非您使用的是基于本周开始(星期日午夜)的GPS时间,否则不需要知道GPS闰秒。

如果您试图从“从一周开始的GPS时间”转换,那么您还需要知道当前的GPS week number以将“一周的GPS时间”转换为UTC。

ublox设备报告一些时间戳为“从一周开始GPS毫秒”的修复信息,This NeoGPS file显示了在“从一周开始GPS毫秒”和UTC之间转换的几种方法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GPS时间UTC时间是两种不同的时间标准,它们之间的换需要考虑到时区以及闰秒等因素。以下是一个简单的Python示例代码,用于将GPS时间换为UTC时间: ```python import datetime def gps_week_second_to_utc(gps_week, gps_second): # GPS起始时间(1980年1月6日 00:00:00 UTCgps_epoch = datetime.datetime(1980, 1, 6, 0, 0, 0) # GPS换为秒数 gps_time = gps_week * 604800 + gps_second # 计算UTC时间 utc_time = gps_epoch + datetime.timedelta(seconds=gps_time) # 考虑闰秒 leap_seconds = get_leap_seconds(utc_time.year, utc_time.month) utc_time += datetime.timedelta(seconds=leap_seconds) return utc_time def get_leap_seconds(year, month): # 闰秒列表 leap_seconds_list = [ (1981, 7), (1982, 7), (1983, 7), (1985, 7), (1988, 1), (1990, 1), (1991, 1), (1992, 7), (1993, 7), (1994, 7), (1996, 1), (1997, 7), (1999, 1), (2006, 1), (2009, 1), (2012, 7), (2015, 7), (2016, 12), (2017, 12), (2018, 12), (2019, 12), (2021, 12) ] leap_seconds = 0 for leap_year, leap_month in leap_seconds_list: if year > leap_year or (year == leap_year and month >= leap_month): leap_seconds += 1 return leap_seconds ``` 使用示例: ```python utc_time = gps_week_second_to_utc(2154, 432000) print(utc_time.strftime('%Y-%m-%d %H:%M:%S')) # Output: 2022-03-01 00:00:00 ``` 该示例代码可以将GPS时间(2154,432000秒)换为UTC时间(2022年3月1日0时0分0秒)。如果需要将UTC时间换为GPS时间,也可以编写类似的代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值