'yyyy-mm-dd hh:mm a' inputFormat in 'datetime' function
47 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yu Li
am 24 Feb. 2022
Kommentiert: Yu Li
am 24 Feb. 2022
Hi:
I'm trying to convert a string to datetime, below are the result of two command:
datetime('2022-02-22 9:30 am','InputFormat','yyyy-mm-dd hh:mm a','TimeZone', 'America/New_York')
ans = 22-Jan-2022 09:30:00
datetime('2022-02-22 9:30 am','TimeZone', 'America/New_York')
ans = 22-Feb-2022 09:30:00
the 2nd returns the result I want, but I'm interest to know why the 1st is wrong.
Thanks!
Yu
0 Kommentare
Akzeptierte Antwort
the cyclist
am 24 Feb. 2022
The warning message you got from the first line tells you exactly what the problem is:
datetime('2022-02-22 9:30 am','InputFormat','yyyy-mm-dd hh:mm a','TimeZone', 'America/New_York')
You needed
datetime('2022-02-22 9:30 am','InputFormat','yyyy-MM-dd hh:mm a','TimeZone', 'America/New_York')
5 Kommentare
the cyclist
am 24 Feb. 2022
Bearbeitet: the cyclist
am 24 Feb. 2022
Warnings are on by default. In your instance of MATLAB, this warning -- or possibly all warnings -- must have been turned off. I would recommended looking at this documentation, to understand how warnings get suppressed and restored.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time 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!