简介
我们常用时(hour)分(minute)秒(second)来表示时间。
1 h=60 m,1 m=60 s ,1 h=3600 s。
这里我们利用Matlab,给出了两种格式相互转换的函数。
时分秒转换为秒数的函数
function seconds = hms2s(hour, minute, second)
% hour, minute and second to seconds
% e.g., seconds = hms2s(15, 5, 30)
% Yuechu Wu
% 12131066@mail.sustech.edu.cn
% 2022-09-13
seconds = hour*3600 + minute*60 + second;
end
秒数转换为时分秒的函数
function [hour, minute, second] = s2hms(seconds)
% seconds to hour, minute and second
% e.g., [hour, minute, second] = s2hms(54330)
% Yuechu Wu
% 12131066@mail.sustech.edu.cn
% 2022-09-13
hour = fix(seconds/3600);
minute = fix((seconds - hour*3600)/60);
second = seconds - hour*3600 - minute*60;
end