convert character date string to date vector

조회 수: 5 (최근 30일)
Charles
Charles 2019년 2월 4일
댓글: YT 2019년 2월 4일
Hello
I have a date character string in the following format "2014-07-03T04:00:00.000000Z" within a table structure. I wish to convert this to a format which I can plot on a graph axis using the plot function.
plot(x,y)
where x is the date and y is some time series of data.
How can i convert the current date format?

답변 (1개)

YT
YT 2019년 2월 4일
편집: YT 2019년 2월 4일
You can use datetime to do it
myString = '2014-07-03T04:00:00.000000Z';
myDateString = datetime(myString,'InputFormat','yyyy-MM-dd''T''HH:mm:ss.SSS''Z','TimeZone','UTC');
dateOnly = myDateString; %create copy for dates
timeOnly = myDateString; %create copy for times
dateOnly.Format = 'dd-MM-yyyy'; %dates / x
timeOnly.Format = 'HH:mm:ss.SSS'; %times / y
or use regular expressions
D = regexp(input,'(?<date>.*?)T(?<time>.*?)Z','names');
%D.date = '2014-07-03'
%D.time = '04:00:00.000000';
  댓글 수: 2
madhan ravi
madhan ravi 2019년 2월 4일
편집: madhan ravi 2019년 2월 4일
input() is an in-built function so naming a variable as input is not a good idea.
YT
YT 2019년 2월 4일
ah thanks, changed it ;)

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

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by