필터 지우기
필터 지우기

How do I convert a string to a date?

조회 수: 2 (최근 30일)
ARGY B
ARGY B 2019년 8월 14일
댓글: Star Strider 2019년 8월 15일
I have a txt file with dates in the following form:
200309302300
200309302310
200309302320
......etc
How can I convert these strings into date form?
something like : 2003-Sep-30 23:00 or 2003-09-30 23:00

채택된 답변

Star Strider
Star Strider 2019년 8월 14일
I am not certain if the numbers are themselves strings, or numbers.
If they are numbers, this works:
numdate = [200309302300
200309302310
200309302320];
dn = datenum(num2str(numdate), 'yyyymmddHHMM') % Date Numbers
dv = datevec(dn)
dt = datetime(num2str(numdate), 'InputFormat','yyyyMMddHHmm') % ‘datetime’ Array
If they are strings, omit the str2num calls and just insert them directly.
  댓글 수: 2
ARGY B
ARGY B 2019년 8월 15일
Thank you :)
Star Strider
Star Strider 2019년 8월 15일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by