Converting text to dates with datenum. A problem concerning milliseconds.

조회 수: 5 (최근 30일)
Hi!
I'm trying to convert a large cell of text (containing about 13 million rows) with date information into a date or numbers format.
The text looks like this
'20160405 16:00:00:106'
I'm trying
% datetime(T,'InputFormat','yyyyMMdd HH:mm:ss:SSS')
but it keeps cutting the milliseconds.
05-Apr-2016 16:00:00
I've done some googling and searched here but I couldn't come up with a solution yet. Thanks for the help!

채택된 답변

Steven Lord
Steven Lord 2018년 6월 13일
Build the datetime.
T = '20160405 16:00:00:106'
fmt = 'yyyyMMdd HH:mm:ss:SSS';
dt = datetime(T, 'InputFormat', fmt)
What display format is dt using?
dt.Format
Make it use the same format as T was in.
dt.Format = fmt
  댓글 수: 2
Ben
Ben 2018년 6월 13일
Yep. This is it. Thanks! Simple stuff :)
Steven Lord
Steven Lord 2018년 6월 14일
If you wanted to do this all in one line, you could set the Format in the same command in which you created the datetime.
dt = datetime(T, 'InputFormat', fmt, 'Format', fmt)

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by