Convert Milliseconds to Clock time from excel file
1 回表示 (過去 30 日間)
古いコメントを表示
Hello! I am hoping to understand how to convert milliseconds to the format hh:mm:ss.SS
Ie I have the value 1063987 milliseconds and want to convert it to hh:mm:ss.SS time format
Furthermore, I have all the values in an excel file and would like the values pulled from there. Otherwise, if possible an inital line where we could specify teh value of variable (ie x = 1063987, and then have x be throughout the remaining code)
thank you for any insight into this!
0 件のコメント
回答 (1 件)
Jim Riggs
2019 年 11 月 1 日
Let X be the time in miliseconds.
Xs = X/1000; % the total time in seconds
Hour = floor(Xs/3600) ; % The number of hours in x
Min = floor((Xs - Hour*3600) / 60); % the number of minutes
Sec = Xs - Hour*3600 - Min*60; % the number of seconds
1 件のコメント
Jim Riggs
2019 年 11 月 1 日
Make it a function:
function [Hour, Min, Sec] = mstoHMS(X)
Xs = X/1000;
Hour = floor(Xs/3600);
Min = floor((Xs - Hour*3600)/60);
Sec = Xs - Hour*3600 - Min*60;
end
You could also add Days to the function:
function [Day, Hour, Min, Sec] = mstoDHMS(X)
Xs = X/1000;
Day = floor(Xs/86400);
Hour = floor((Xs - Day*16400)/3600);
Min = floor((Xs - Day*86400 - Hour*3600)/60);
Sec = Xs - Day*86400 - Hour*3600 - Min*60;
end
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!