Matlab calculates the end time from the start time and duration

1. According to the function format, enter the start time and duration.

Insert picture description here

2. Run the program and calculate the end time.

Insert picture description here

3. Source code

function y=tool1finish_time(start_time,time_len)

%   起始时间--时、分、秒
start_hou=start_time(1);
start_min=start_time(2);
start_sec=start_time(3);

%   结束时间--时、分、秒
temp=start_sec+start_min*60+start_hou*3600+time_len;
finish_hou=floor(temp/3600);
finish_min=floor((temp-3600*finish_hou)/60);
finish_sec=temp-finish_hou*3600-finish_min*60;

%输出显示
finish_time=[num2str(finish_hou),' : ',num2str(finish_min),' : ',num2str(finish_sec)]

%   返回值y--[时 分 秒]
y=[finish_hou finish_min finish_sec];
end

Guess you like

Origin blog.csdn.net/peter_young1990/article/details/114339159