UTC与GPS时间转换-[week, sow]
- utc2gps
- gps2utc
- 测试
- 参考
Ref: Global Positioning System
utc2gps
matlab源码
function res = utc2gps(utc_t, weekStart)%% parameterssec_day = 86400;sec_week = 604800;leapsec = 18; % 默认周一为一周的开始if nargin < 2weekStart = datenum('1980-01-06 00:00:00'); % 默认周一为一周的开始weekStart = weekStart * sec_day - leapsec;endutc_t_num = datenum(utc_t) * sec_day;gps_week = floor((utc_t_num - weekStart)/sec_week);gps_sec = mod((utc_t_num - weekStart), sec_week);gps_sec = round(gps_sec, 3);res = [gps_week, gps_sec];
end
gps2utc
matlab源码
function res = gps2utc(week_num, sow) %% parameterssec_day = 86400;sec_week = 604800;leapsec = 18; % 默认周一为一周的开始if nargin < 2sow = 0;endweekStart = datenum('1980-01-06 00:00:00'); % from start timeweekStart = weekStart * sec_day - leapsec;dnum = (week_num * sec_week + sow + weekStart)/sec_day; % unit: dayres = datetime(dnum,'ConvertFrom','datenum');
end
测试
clear
close alladdpath 'obs_read_lib/'
% 创建一个datetime对象
date = [2024 05 26 00 00 00.200000];
t = datetime(date);% 转换为SOW
gps_t = utc2gps(t);
date_re = gps2utc(gps_t(:,1),gps_t(:,2));
gps_t_check = utc2gps(date_re);
% 显示结果
disp(gps_t);
参考
GPS 时间转换在线工具