UTC时间到Python时间转换器 [英] UTC time to GPS time converter by Python

查看:472
本文介绍了UTC时间到Python时间转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UTC时间(纪元Unix时间),格式化为时间戳如下。

1496224620

值:2017年5月31日09:57:00)

我需要将格式化为Unix时间的时间戳转换为GPS时间格式,如下所示。

1180259838

(人类可读值:2017年5月31日09:57:00)

我需要一个python程序(算法对我来说很好),可以将格式化为Unix时间的时间戳转换为格式化为GPS时间的时间戳。



有一个PHP程序可以做所以。我可以从PHP代码更改为Python代码,以便自己创建一个Python程序。但我认为也有一个简短的方法(Python的内置函数),可以实现我的期望更有效。

这里是PHP程序的链接

https://www.andrews.edu/~tzs/timeconv/timealgorithm.html

解决方案

只需从UNIX时间减去315964782即可。



GPS Time starts在1980年1月5日。UNIX时间从1970年1月1日开始。它们只有不同的起点,或 Epochs 。这两个时代之间的差异是这两个日期之间的秒数 PLUS 18 GPS闰秒(到目前为止)。 其他人有注意到,随着地球自转速度逐渐减慢,定期添加 GPS闰秒


我们必须在每次闰秒发生时手动更新源代码(例如2018年,2019年,...)是否有任何可行的方法来防止这个问题?

许多设备都有一条消息,指示当前有效的GPS秒数。我的C ++ NeoGPS 库有一个示例程序,它从ublox设备请求当前的GPS秒数(二进制消息定义 here )。有关NAV-TIMEGPS消息的更多信息,请参见ublox NEO-xx规范。其他制造商可能有自己的协议和消息,以获得当前的GPS闰秒。



然而:



大多数GPS设备都以UTC为单位报告时间,闰秒已包含在内。除非您使用基于星期一(星期日午夜)的GPS时间,否则您不需要知道GPS闰秒。

如果您尝试从星期开始以来的GPS时间转换,然后您还需要知道当前的 GPS周数,以将GPS周时间转换为UTC。



ublox设备报告一些固定信息,其时间戳为自周开始以来的GPS毫秒数。 这个NeoGPS文件显示了几种在GPS毫秒自周开始和UTC。


I have a UTC time (epoch Unix time) formatted as timestamp as below.
1496224620
(Human readable value: May 31, 2017 09:57:00)

I need to convert the timestamp formatted as Unix time into GPS time format as below.
1180259838
(Human readable value: May 31, 2017 09:57:00)

I need a python program (algorithm is fine for me) to convert timestamp formatted as Unix time to timestamp formatted as GPS time.

There is one PHP program to do so. I can change from PHP code to Python code to have a Python program by myself. But I think there is also a short way (built-in function of Python) that can implement my expectation more effective.
Here is the link of PHP program
https://www.andrews.edu/~tzs/timeconv/timealgorithm.html

解决方案

Just subtract 315964782 from the UNIX time.

GPS Time starts on January 5, 1980. UNIX time starts on January 1, 1970. They simply have different starting points, or Epochs. The difference between those two Epochs is the number of seconds between those two dates PLUS 18 GPS leap seconds (so far).

As others have noted, GPS leap seconds are periodically added as the Earth's rotation gradually slows.

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?

Many devices have a message that indicates the "current" number of GPS seconds in effect. My C++ NeoGPS library has an example program that requests the current number of GPS seconds from a ublox device (binary message defined here). See ublox NEO-xx specifications for more information regarding the NAV-TIMEGPS message.

Other manufacturers may have their own protocols and messages for obtaining the current GPS leap seconds.

HOWEVER:

Most GPS devices report times in UTC, with the leap seconds already included. Unless you are using a GPS time based on the start of the week (midnight Sunday), you should not need to know the GPS leap seconds.

If you are trying to convert from a "GPS time since start of week", then you would also need to know the current GPS week number to convert "GPS time of week" to UTC.

ublox devices report some fix information with a timestamp that is "GPS milliseconds since start of week." This NeoGPS file shows several methods for converting between "GPS milliseconds since start of week" and UTC.

这篇关于UTC时间到Python时间转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆