Converting GPS time to Local Time
84 views (last 30 days)
Show older comments
hi. Im relatively new to Matlab and i have been trying to analyze a set of GPS data which has the time of the day in GPS format. the raw data has time of day stored in a matlab variable 't' as:
432060
432060
432120
432180
432180
432240
432240
432300
432300
432360
432360
432420
432420
432480
432480
432540
432540...
The difference between 2 consecutive GPS time is 60 sec. some time values are repeated, meaning 2 readings where taken for that particular minute.
i.e.
432060= 00:01 UT= 12:01 LT
402060= 00:01 UT= 12:01 LT
432120= 00:02 UT= 12:02 LT
and so forth
I have been trying to convert this 6 digit numbers stored in variable 't' to HH:MM LT format (storing it in variable t2) using various examples and codes on this forum and from YouTube but have so far failed.
i would be grateful if someone can help me with the conversion. btw Fiji time is UT +12hr.
0 Comments
Accepted Answer
jonas
on 27 May 2018
Edited: jonas
on 27 May 2018
t2=datestr(seconds(t)+hours(12),'HH:MM')
3 Comments
Peter Perkins
on 8 Jun 2018
If possible, just make datetimes to begin with:
>> gpsSecondsOfWeek = [432060; 432060; 432120]
gpsSecondsOfWeek =
432060
432060
432120
>> gpsWeekStart = datetime(2018,6,3,'TimeZone','UTC')
gpsWeekStart =
datetime
03-Jun-2018
>> timestamp = gpsWeekStart + seconds(gpsSecondsOfWeek)
timestamp =
3×1 datetime array
08-Jun-2018 00:01:00
08-Jun-2018 00:01:00
08-Jun-2018 00:02:00
>> localTimestamp = datetime(timestamp,'TimeZone','Pacific/Fiji')
localTimestamp =
3×1 datetime array
08-Jun-2018 12:01:00
08-Jun-2018 12:01:00
08-Jun-2018 12:02:00
Note that Fiji is UTC+12 for only part of the year, so your code will be off by an hour half the time. Using datetime takes care of that.
The other thing is that as long as your week doesn't include a leap second, you're OK with being simple, because you're counting seconds from "start of week". But at some point, there will be another leap second at 30 Jun or 31 Dec, and you'll need to account for that if you expect to end up with the correct local time during that week.
MATLAB supports leap seconds if you set the time zone to 'UTCLeapSeconds', so it's a simple change.
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!