datetime InputFormat is returning month for minutes
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Scott
am 18 Jul. 2025
Verschoben: Walter Roberson
am 22 Jul. 2025
I'm very confused by the behavior of the datetime InputFormat string in MATLAB.
I have a date string such as "2025040901:42:23 PM"
I believe I am correctly using MM for two-digit month and mm for twelve-hour two-digit minutes. Why is the month always being returned as the minutes?
>> s = "2025040901:42:23 PM"
s =
"2025040901:42:23 PM"
>> datetime(s, 'InputFormat', 'yyyyMMddhh:mm:ss a')
ans =
datetime
2025-04-09 13:04:23
Change the month to prove that that is what is being shown.
>> s = "2025060901:42:23 PM"
s =
"2025060901:42:23 PM"
>> datetime(s, 'InputFormat', 'yyyyMMddhh:mm:ss a')
ans =
datetime
2025-06-09 13:06:23
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 18 Jul. 2025
Bearbeitet: Fangjun Jiang
am 18 Jul. 2025
It is correct running your code here in R2024b.
s = "2025040901:42:23 PM";
datetime(s, 'InputFormat', 'yyyyMMddhh:mm:ss a')
s = "2025060901:42:23 PM";
datetime(s, 'InputFormat', 'yyyyMMddhh:mm:ss a')
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Calendar finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!