Converting GPS time to Local Time

67 次查看(过去 30 天)
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.

采纳的回答

jonas
jonas 2018-5-27
编辑:jonas 2018-5-27
t2=datestr(seconds(t)+hours(12),'HH:MM')
  3 个评论
Peter Perkins
Peter Perkins 2018-6-8
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 2018-7-17
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by