Azzera filtri
Azzera filtri

Converting GPS time to Local Time

68 visualizzazioni (ultimi 30 giorni)
Sarvesh Kumar
Sarvesh Kumar il 27 Mag 2018
Commentato: Sarvesh Kumar il 17 Lug 2018
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.

Risposta accettata

jonas
jonas il 27 Mag 2018
Modificato: jonas il 27 Mag 2018
t2=datestr(seconds(t)+hours(12),'HH:MM')
  3 Commenti
Peter Perkins
Peter Perkins il 8 Giu 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.
Sarvesh Kumar
Sarvesh Kumar il 17 Lug 2018
Hi. My analysis does not require the time to be exactly accurate, so the leap second will not really matter (i can allow tolerance of up to 10sec). however, i have noted your point just in case i have to change something which may lead to considering the leap seconds as well.
thanks once again

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by