Yusheng
Yusheng

Reputation: 23

Why do datestr(x) and datestr(x,'hh:mm:ss') in Matlab have different time result?

I have the following date in serial numbers

>> x

x =

7.3506e+05

and below are the two different results:

>> datestr(x)

ans =

11-Jul-2012 15:58:00

>> datestr(x,'hh:mm:ss')

ans =

15:07:00

Does anyone know why this happens?

Upvotes: 2

Views: 31

Answers (1)

beaker
beaker

Reputation: 16801

Because mm means "Month in two digits", and since the month is July, "07" is correct.

Use upper case for time: "HH:MM:SS"

http://www.mathworks.com/help/matlab/ref/datestr.html#input_argument_formatout

>> x
x =    7.3506e+05
>> datestr(x)
ans = 11-Jul-2012 15:58:00
>> datestr(x,'HH:MM:SS')
ans = 15:58:00

Upvotes: 4

Related Questions