필터 지우기
필터 지우기

Conversion of string containing "AM" or "PM" to datetime

조회 수: 57 (최근 30일)
Sebastian
Sebastian 2022년 4월 21일
편집: Stephen23 2022년 4월 21일
Given the string
str = "4/21/2022 8:48:40 AM"
I want to convert it to a datetime
datetime
21-Apr-2022 08:48:40
However, using
d = datetime(str, "InputFormat", "MM/dd/yyyy HH:mm:SS")
gives an error, while
d = datetime(str, "InputFormat", "MM/dd/yyyy HH:mm:SS a")
gives
datetime
21-Apr-2022 00:48:00
what is not what I want or even expect (hours and seconds both set to zero).

채택된 답변

Stephen23
Stephen23 2022년 4월 21일
편집: Stephen23 2022년 4월 21일
str = "4/21/2022 8:48:40 AM";
dtm = datetime(str, "InputFormat", "M/d/u h:m:s a")
dtm = datetime
21-Apr-2022 08:48:40

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by