How to I convert this time format to datetime?
조회 수: 10 (최근 30일)
이전 댓글 표시
I got this strange time format: my str ='Fri May 28 18:15:46 +0000 2021'.
I would be very happy if I could get it down to '28-May-2021 18:15:46'.
Tried messing with datetime(), but with no luck
Thank in advance
댓글 수: 0
채택된 답변
Steven Lord
2021년 5월 28일
str ='Fri May 28 18:15:46 +0000 2021'
inputFormat = 'eee MMM d H:mm:ss xx yyyy'
dt = datetime(str, 'InputFormat', inputFormat, 'TimeZone', 'UTC')
I used the information in the description of the Format property on the documentation page for the datetime function to generate inputFormat. Most of the identifiers were in the "All Date and Time Formats" table. I wasn't sure whether you wanted to use Z, xx, or xxxx. When I tried just using the InputFormat name-value pair input MATLAB threw an error that indicated I needed to specify a TimeZone as well.
댓글 수: 0
추가 답변 (1개)
Walter Roberson
2021년 5월 28일
str ='Fri May 28 18:15:46 +0000 2021'
datetime(str, 'inputformat', 'eee MMM dd HH:mm:ss Z yyyy','timezone','utc')
댓글 수: 2
Walter Roberson
2023년 1월 10일
GazeTimestamp = [1535.81; 169225; 1614.36; 1254.72]
D = seconds(GazeTimestamp ./ 1000);
D.Format = 'hh:mm:ss'
참고 항목
카테고리
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!