milliseconds time conversion problem
조회 수: 5 (최근 30일)
이전 댓글 표시
I'm trying to print the milliseconds field with the following
DS = datestr(MM,'HH:MM:SS.FFF')
the SS.FFF field is rounded up to the nearest second
ie. 59.000
So on the command line I input
K>>MM = .9833
then K>> ZZ = MM * 60.00
the returned value for ZZ on the command line is
59.00
The interpreter shouldn't know if this is anything other than a double multiplied by a double returning a double not a time value.
How do I get around this and how can I print HH:MM:SS.FFF in my code?
댓글 수: 4
Walter Roberson
2011년 6월 23일
JD = 97.9833
>> datestr(JD,'HH:MM:SS.FFF')
ans =
23:35:57.120
Notice this is different than the times you get. I am using 2008b.
It does not appear to be single() vs double() as in my release datestr() will not accept single()
Arithmetically, consider
>> .9833 * 24*60
ans =
1415.952
That is, 0.9833 of a day is 1415 full minutes and 0.952 partial minutes. Multiply that by 60 and you get 57.12 -- 57 seconds and 120 milliseconds, just as is calculated on my system.
Please repeat those calculations on your system and see what gets returned.
Walter Roberson
2011년 6월 23일
Note that if JD is a Julian Day then there needs to be a 1/2 day conversion and possibly a timezone conversion in order to get the local time. There are different Julian Day standards with different corrections; see http://en.wikipedia.org/wiki/Julian_day
These corrections could account for the hour discrepency (23 vs 17), but I do not see how they could account for the difference in minutes and seconds.
답변 (2개)
Walter Roberson
2011년 6월 23일
Michael, which MATLAB version are you using?
Also please check that none of your values are single precision numbers. In the time range of today, eps(datenum(now)) is about 11/10 of a millisecond so if you were using single precision or a far future date, you could run out of precision.
댓글 수: 3
Walter Roberson
2011년 6월 24일
That one is 52.9999996799961 seconds. Is it important that those 3/10-millionth of a second cause the result to be output as 52.999 ?
Michael
2011년 6월 23일
댓글 수: 5
Walter Roberson
2011년 6월 24일
fix() and floor() truncate.
What you are looking at came in in R14, long before the R2008b that I am using, so it would not be responsible for any differences.
참고 항목
카테고리
Help Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!