time difference(milliseconds) at midnight error!

조회 수: 3 (최근 30일)
rnd rnd
rnd rnd 2018년 11월 20일
편집: Walter Roberson 2018년 11월 21일
Hello,
I am calcualting the time diffrence beetwen a set of values (duration) , it`s working but calculating t.d. at midnight gives me wrong answer:
for i=6:100
disp(milliseconds(td(i) - td(i-5)) - 20000);
end
I have the -20000 bc I always have a 20 seconds delay , I am only interested in the ms without the 20 s
example of my td :
....
'23:59:55'
'23:59:56'
'23:59:56'
'00:00:16'
'00:00:16'
'00:00:17'
'00:00:17'
'00:00:17'
'00:00:37'
'00:00:37'
....
and the output is :
748
748
748
-86399252
-86399236
-86399252
-86399252
-86399252
748
732
until midnight all the values are correct , I calculated them myself,.
how can I solve the problem for the midnight time diff?
*I am using matlab R2017b
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 11월 20일
if those are duration objects that are all less than 24 hours then the output would appear to be correct.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 11월 21일
편집: Walter Roberson 2018년 11월 21일
ntd = td(:)+cumsum([0;diff(td(:))<0])*days(1);
Now apply your code to ntd .

추가 답변 (1개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by