Time difference between two sets of times in hrs mins and seconds.. GUI if possible
1 回表示 (過去 30 日間)
古いコメントを表示
採用された回答
Thomas
2011 年 10 月 19 日
Hi Sharon, I have written a code for this a long time ago. Hope this helps..
close all
% Prompt to enter the time using GUI
prompt ={'Enter Start time and End time:'};
dlg_title = 'Time difference calculator';
num_lines=1;
def={'0 0 0 1 1 1'};
str1 = inputdlg(prompt,dlg_title,num_lines,def);
time1=str2num(str1{1});
% get the times
time1hr=time1(1);
time1min=time1(2);
time1sec=time1(3);
time2hr=time1(4);
time2min=time1(5);
time2sec=time1(6);
time1out=(time1hr*60*60)+(time1min*60)+time1sec;
time2out=(time2hr*60*60)+(time2min*60)+time2sec;
% actual calculation
diffInSec=time2out-time1out
diffInMin=diffInSec/60
if diffInMin >60
Hrs=(diffInMin/60)-mod(diffInMin/60,1)
minutes=diffInMin-(Hrs*60)-mod(diffInMin,1)
seconds=diffInSec-(Hrs*60*60)-(minutes*60)
else
afterdecimal=mod(diffInMin,1);
minutes=diffInMin-afterdecimal
seconds=diffInSec-(minutes*60)
end
その他の回答 (2 件)
Sean de Wolski
2011 年 10 月 19 日
So start by opening GUIDE
guide %at the command line
Then draw the GUI so that it has edit boxes to enter times, static boxes to give directions, and a push button to press to give you the times. After that, write the functions to do the work. Or write the functions to do the work first and then add them to a GUI. Ask specific detailed MATLAB questions here when you get stuck.
Welcome to MATLAB Answers!
Real User
2023 年 1 月 20 日
>> duration("11:01:00")-duration("10:00:00")
ans =
duration
01:01:00
>> string(duration("11:01:00")-duration("10:00:00"))
ans =
"01:01:00"
>> [h, m, s]=hms(duration("11:01:00")-duration("10:00:00"))
h =
1
m =
1
s =
0
>> d = duration(h,m,s)
d =
duration
01:01:00
These work even if you include the dates.
[m,d,t] = split(T,{'months','days','time'})
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!