Convert Milliseconds to Clock time from excel file

4 visualizaciones (últimos 30 días)
Rohini Bagrodia
Rohini Bagrodia el 1 de Nov. de 2019
Comentada: Jim Riggs el 1 de Nov. de 2019
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!

Respuestas (1)

Jim Riggs
Jim Riggs el 1 de Nov. de 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 comentario
Jim Riggs
Jim Riggs el 1 de Nov. de 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

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by