milliseconds time conversion problem

4 vues (au cours des 30 derniers jours)
Michael
Michael le 23 Juin 2011
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
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
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.

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
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
Michael
Michael le 23 Juin 2011
Hi Walter,
I found this under Serial Number Dates;
Working with Serial Date Numbers
A serial date number represents a calendar date as the number of days that has passed since a fixed base date.
In MATLAB, serial date number 1 is January 1, 0000. MATLAB also uses serial time to represent fractions of days beginning at midnight; for example, 6 p.m. equals 0.75 serial days. So the string '31-Oct-2003, 6:00 PM' in MATLAB is date number 731885.75.
The fractional part is the only part of interest in the time calculation. Could it be a problem with verion 2010b?
Different input value this time.....
K>> Billy= datestr(.7283912037,'HH:MM:SS.FFF')
Billy =
17:28:53.000
Walter Roberson
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 ?

Connectez-vous pour commenter.


Michael
Michael le 23 Juin 2011
Hi Walter, I'm using 2010b. I was wondering about a type mismatch issue but here's another pass at the command line.
K>> datestr(.734016203670760,'ss.FFF')
ans =
59.000
Looks like something internal to the datestr f(x).
  5 commentaires
Walter Roberson
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.
Walter Roberson
Walter Roberson le 24 Juin 2011
sprintf('%02d:%02d:%02d', floor(HH), floor(MM), floor(Secs))

Connectez-vous pour commenter.

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!

Translated by