an issue with datetime
4 次查看(过去 30 天)
显示 更早的评论
hi
defined a variable:
a = '02/15/2023 12:59:58';
did:
b = datetime(a,'InputFormat','MM/dd/yyyy hh:mm:ss')
i get:
15-Feb-2023 00:59:58
checked the time zone and also imposed the 'TimeZone' option.
thanks a lot !!!
mat
3 个评论
Steven Lord
2023-3-8
Unable to convert '02/15/2023 13:00:00' to datetime using the format 'MM/dd/yyyy hh:mm:ss'. ???
That's correct. Looking at the table of letter identifiers in the documentation for the Format property of datetime objects the description of the 'hh' identifier is "Hour, 12-hour clock notation using two digits". On a 12-hour clock 13 is not a valid hour.
Now if you were to use "HH", whose description states "Hour, 24-hour clock notation using two digits", instead of "hh" then hour 13 is 1 PM.
a = '02/15/2023 13:00:00';
d = datetime(a,'InputFormat','MM/dd/yyyy HH:mm:ss')
If you want to show the AM/PM period, the identifier for that is 'a'. If I specify the period I probably also want to use the 12-hour clock so I changed "HH" back to "hh".
d.Format = 'MM/dd/yyyy hh:mm:ss a'
采纳的回答
Voss
2023-3-6
Maybe you mean "HH"
a = '02/15/2023 13:00:00';
b = datetime(a,'InputFormat','MM/dd/yyyy HH:mm:ss')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!