Could not recognize the format of the date/time text
조회 수: 13 (최근 30일)
이전 댓글 표시
I have a timetable with a time column containing microsecond resolution. The time column contains something like this:
"07/04/2021 07:55:27.502.118"
"07/04/2021 07:55:27.502.196"
"07/04/2021 07:55:27.502.274"
"07/04/2021 07:55:27.502.352"
"07/04/2021 07:55:27.502.430"
"07/04/2021 07:55:27.502.508"
How can i process the data using datetime function?
댓글 수: 0
채택된 답변
Stephen23
2022년 10월 4일
C = ["07/04/2021 07:55:27.502.118"
"07/04/2021 07:55:27.502.196"
"07/04/2021 07:55:27.502.274"
"07/04/2021 07:55:27.502.352"
"07/04/2021 07:55:27.502.430"
"07/04/2021 07:55:27.502.508"];
D = datetime(regexprep(C,'\.(\d+)$','$1'), 'InputFormat','d/M/y H:m:s.SSSSSS');
Checking:
D.Format = 'MM/dd/yyyy HH:mm:ss.SSSSSS'
추가 답변 (1개)
Eric Delgado
2022년 10월 4일
You can't. The precision of datetime is milliseconds, but you can use regexp.
inData = "07/04/2021 07:55:27.502.118";
regData = regexp(inData, '(?<timestamp_ms>\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}.\d{3}).(?<us>\d*)', 'names')
outData = datetime(regData.timestamp_ms, 'InputFormat', 'dd/MM/yyyy HH:mm:ss.SSSSSS') + seconds(str2double(regData.us)/1e+6)
format long
second(outData)
댓글 수: 2
Eric Sofen
2022년 10월 4일
To be clear, datetime supports more than milliseconds. In fact, datetime guarantees at least nanosecond precision.
참고 항목
카테고리
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!