milliseconds time conversion problem
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 23 Juin 2011
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
le 23 Juin 2011
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.
Réponses (2)
Walter Roberson
le 23 Juin 2011
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 commentaires
Walter Roberson
le 24 Juin 2011
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
le 23 Juin 2011
5 commentaires
Walter Roberson
le 24 Juin 2011
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.
Voir également
Catégories
En savoir plus sur Calendar dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!