python获取系统当前时间并转utc时间为绝对秒数,UTC时间到Python时间转换器

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值