Utc Time To Gps Time Converter By Python
Solution 1:
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.
Solution 2:
How about:
import datetime
datetime.datetime.fromtimestamp(int("1284101485")).strftime('%B-%Y-%d %H:%M:%S')
Post a Comment for "Utc Time To Gps Time Converter By Python"