Convert Time Given in Seconds to Minute, Seconds, Milliseconds
조회 수: 165 (최근 30일)
이전 댓글 표시
Hi all,
I am trying to convert a time given in seconds such as 183.55s into minute, seconds, milliseconds.
For minute, I'm using: init_mn=fix(init_time/60), which gives me the correct answer.
How can I obtain the seconds and miliseconds without rounding?
Thank you in advance!
댓글 수: 0
답변 (4개)
Star Strider
2021년 8월 5일
This is simply a straightforward format change:
t = seconds(183.55)
t.Format = 'hh:mm:ss.SSS'
producing the desired result.
.
댓글 수: 0
Chunru
2021년 8월 5일
[h, m, s] = hms(duration([0 0 183.55]))
% for sec and fractional sec
si = floor(s)
sf = s-si
댓글 수: 0
Stephen23
2021년 8월 5일
If you really need minutes (i.e. and not roll-over to hours for >59 minutes) then you can calculate this yourself, e.g.:
inp = 7654.321; % time in seconds
t_min = ceil(1000*inp);
t_ms = mod(t_min,1000) % milliseconds
t_min = fix(t_min/1000);
t_sec = mod(t_min,60) % seconds
t_min = fix(t_min/60) % minutes
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!