MATLAB Answers

datetime default stetings 12/24

조회 수: 12(최근 30일)
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

로그인 to comment.

채택된 답변

Are Mjaavatten
Are Mjaavatten 10 Aug 2019
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

Guillaume
Guillaume 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

로그인 to comment.

More Answers (1)

Lieke Numan
Lieke Numan 13 Aug 2019
Thanks a lot!

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by