-1

As a part of my Master's project I collect data with an RTK receiver and for matching some x,y,z,time data with scientific measurements I need to convert some GPS time ( GPS Week & Milliseconds since the beginning of the GPS week) to UTC (hh:mm:ss:ms). Can someone instruct me?

For example: data example to convert Cheers

oriahu
  • 1
  • 1
  • Does this answer your question? [how to convert GPS time composed of Time, weeks and leap seconds to UTC Timestamp](https://stackoverflow.com/questions/58695004/how-to-convert-gps-time-composed-of-time-weeks-and-leap-seconds-to-utc-timestam) – Wolfgang Kuehn Jan 26 '22 at 22:05
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 02 '22 at 06:00

1 Answers1

0

Can you try the following:

from datetime import datetime, timedelta
import pytz

def gps_datetime(time_week, time_ms, leap_seconds=18):
    gps_epoch = datetime(1980, 1, 6, tzinfo=pytz.utc)
    return gps_epoch + timedelta(weeks=time_week, 
                                 milliseconds=time_ms, 
                                 seconds=-leap_seconds)
# from your example
print(gps_datetime(2193, 377638200))

Output:

datetime.datetime(2022, 1, 20, 8, 53, 58, 200000, tzinfo=<UTC>)
Jeril
  • 7,858
  • 3
  • 52
  • 69
  • Tnx for that it works I just need to check that the time is exactly the same on the scientific measurements. – oriahu Jan 24 '22 at 10:54
  • Glad it helped. Happy Coding !!! – Jeril Jan 25 '22 at 02:54
  • I assumed that the 'leap_seconds' parameter should be set to 18 as there are 18 leap seconds so far between the GPS to UTC. I still have a bias between the time after conversion and the UTC time of the measurements I want to match by time. any thoughts? – oriahu Jan 26 '22 at 11:45
  • Updated it to 18. check now. – Jeril Jan 27 '22 at 02:33