Convert Milliseconds to Clock time from excel file
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Jim Riggs
on 1 Nov 2019
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 Comment
Jim Riggs
on 1 Nov 2019
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
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!