How do I convert a specific string to a date ?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi everyone,
I have acceleration measurements that were collected via a tag.
The time is recorded as '22-07-04T013:09:42Z' (it is exactly written like that in my data).
Do you know how I can convert this type of string into a date? And if it possible, select only the time which here would be '13:09:42' ?
I tried datetime and datenum functions but I guess the specific format makes it more complicated.
Thanks,
Marine
댓글 수: 2
Stephen23
2022년 7월 29일
"The time is recorded as '22-07-04T013:09:42Z' (it is exactly written like that in my data)."
Please check your data: it is odd to use three digits for the hours. Otherwise, it looks like a normal ISO 8601 timestamp.
채택된 답변
Star Strider
2022년 7월 29일
That aside, try this—
DT = datetime('22-07-04T013:09:42Z', 'InputFormat','dd-MM-yy''T''HHH:mm:ss''Z''', 'TimeZone','UTC') % Convert To 'datetime'
DT.Format = 'HH:mm:ss' % Select Only Time Time
Here, datetime does not have problems with three-digit hours, providing that the first digit is a 0. I have no idea what it would do otherwise.
.
추가 답변 (0개)
참고 항목
카테고리
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!