📄 utc2gpst.m
字号:
%UTC时转换GPS时
function GPSTime = UTC2GPST(UTC);
year = UTC(1);
month = UTC(2);
day = UTC(3);
hour = UTC(4);
minute = UTC(5);
second = UTC(6);
%将年补齐四位
if year < 100
year = year + 2000;
end
totalDays = 0;
WeekNo = 0;
DaysOfWeek = 0;
GpsTime = 0;
DaysOfMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
%计算不足一年的月的总天数,考虑润年
for m = 1:month-1;
totalDays = totalDays + DaysOfMonth(m);
if(m == 2)
if(rem(year,4) == 0)
totalDays = totalDays + 1;
end
end
end
%加上当前月的日期
totalDays =totalDays + day - 1;
%计算一年的天数,考虑润年
for i = 1980:year-1;
totalDays = totalDays + 365;
if (rem(i,4) == 0)
totalDays = totalDays + 1;
end
end
totalDays = totalDays - 5;%减去八零年一月一日至一月六日的天数
DaysOfWeek = rem(totalDays,7);%不足一周的天数
WeekNo = (totalDays - DaysOfWeek)/7;%星期数
%计算GPST
GPSTime = (hour*3600 + minute*60 + second + DaysOfWeek*24*3600);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -