Converting GPS time to Local Time
조회 수: 68 (최근 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.
댓글 수: 0
채택된 답변
jonas
2018년 5월 27일
편집: jonas
2018년 5월 27일
t2=datestr(seconds(t)+hours(12),'HH:MM')
댓글 수: 3
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!