convert a string into a date and time format
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, How can I convert this string into a date and time format in matlab. The months will be in spanish and the number of letters may vary for the month. This data will be obtained from different files and it will vary.
m ='October17,196616:41:00'
The result should be date_time= 1996/10/17 16:41:00
Thank you
댓글 수: 0
채택된 답변
Star Strider
2023년 1월 4일
Try something like this —
m ='October17,196616:41:00';
DT = datetime(m, 'InputFormat','MMMMdd,yyyyHH:mm:ss', 'Format','yyyy/MM/dd HH:mm:ss')
.
댓글 수: 4
Steven Lord
2025년 3월 11일
If you've imported the data as a string array:
s1 = ["11-Mrz-2025 10:03:47"; "12-Dec-2025 09:22:38"]
s2 = replace(s1, ["Mrz", "Dec"], ["März", "Dez"])
d2 = datetime(s2, Locale="de_DE")
You could write a small helper function, call it standardizeMonth, to perform that replace call to replace any non-standard abbreviations you use.
Star Strider
2025년 3월 11일
@Jim Benjamin — You don’t have to rename all of them, only the non-standard ones.
Also, as I suggested and that @Steven Lord provided an example for, renaming the ones that don’t match MATLAB’s set (see my earlier Comment) can be done in one line using the strrep function.
추가 답변 (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!