Convert Milliseconds to Clock time from excel file
4 次查看(过去 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!