MATLAB Answers

0

datetime default stetings 12/24

Asked by Lieke Numan on 9 Aug 2019
Latest activity Answered by Lieke Numan on 13 Aug 2019
I used datetime.setDefaultFormats('default','hh:mm:ss yyyy-MM-dd') to set my default setting for datetime. However, time is running up to 12 instead of 24 hours. How can I change this?

  0 Comments

Sign in to comment.

2 Answers

Answer by Are Mjaavatten on 10 Aug 2019
 Accepted Answer

Use HH instead of hh for the hours:
>> datetime.setDefaultFormats('default','hh:mm:ss yyyy-MM-dd')
>> t = datetime(2019,8,10,17,30,0)
t =
05:30:00 2019-08-10
>> datetime.setDefaultFormats('default','HH:mm:ss yyyy-MM-dd')
>> t
t =
17:30:00 2019-08-10

  1 Comment

Guillaume
on 10 Aug 2019
See the Format documentation of datetime, which lists all the format and indeed clearly states:
h Hour, 12-hour clock notation using one or two digits
hh Hour, 12-hour clock notation using two digits
H Hour, 24-hour clock notation using one or two digits
HH Hour, 24-hour clock notation using two digits

Sign in to comment.


Answer by Lieke Numan on 13 Aug 2019

Thanks a lot!

  0 Comments

Sign in to comment.