Convert Milliseconds to Clock time from excel file
조회 수: 3 (최근 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!