Get total number of leap seconds relative to gps time

19 ビュー (過去 30 日間)
user86753
user86753 2022 年 10 月 13 日
編集済み: James Tursa 2024 年 11 月 23 日 1:26
I have a gps time stamp from a gps receiver, I'd like to convert that to GMT/UTC date and time.
GpsTime = 1667089162.11771
DayToSecs = 24*60*60;
TimeZero = datetime(1970,1,1, 'Format', 'd-MMM-y HH:mm:ss.SSS Z');
Tvec = GpsTime/DayToSecs + TdmsTimeZero;
Do I need to also adjust for leap seconds? If so, How do I return the total number of leap seconds from 'leapseconds' instead of the timetable?

回答 (2 件)

David Hill
David Hill 2022 年 10 月 13 日
編集済み: David Hill 2022 年 10 月 13 日
As long as the gps collection date is after 1 January 2017, then just subtract 18 seconds (37-19) see
Although your gps time seems to be in the future (not sure why).
GpsTime = 1667089162.11771;
utc=datetime(1980, 1, 6)+seconds(GpsTime-18);
utc=datetime(utc,'Format','yyyy-MM-dd HH:mm:ss.SSS')
utc = datetime
2032-11-03 00:19:04.117

James Tursa
James Tursa 2024 年 11 月 23 日 1:20
編集済み: James Tursa 2024 年 11 月 23 日 1:26
To convert a GPS timestamp to a UTC time, use the UTCLeapSeconds time zone which automatically accounts for leap seconds in the background calculations. E.g.,
GpsTime = 1667089162.11771;
GPS_epoch = datetime(1980,1,6,'TimeZone','UTCLeapSeconds')
GPS_epoch = datetime
1980-01-06T00:00:00.000Z
GPS_epoch + seconds(GpsTime)
ans = datetime
2032-11-03T00:19:04.117Z
My advise is to stick with the UTCLeapSeconds time zone exclusively when working with continuous time scales such as GPS, TT, TAI, etc.
(Same comment as David ... why is this in the future?)
If the timestamp in question is actually seconds from Modern UTC epoch and not GPS time as your post seems to allude to, then the calculations would be:
UtcTime = 1667089162.11771;
UTC_epoch = datetime(1970,1,1,'TimeZone','UTCLeapSeconds')
UTC_epoch = datetime
1970-01-01T00:00:00.000Z
UTC_epoch + seconds(UtcTime)
ans = datetime
2022-10-30T00:18:55.117Z
Now we get something reasonable for the year 2022, but still in the future compared to your post date, so this is still confusing.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by