how to use datetime ?

조회 수: 4 (최근 30일)
pruth
pruth 2020년 11월 19일
편집: Ananthi Jegan 2020년 11월 19일
I am not sure what am i doing wrong here.
jday = '190608' % year month day
datetime(jday, 'InputFormat', 'yyMMDD')
this should give me an out put as 8-june-2019
but instead of that it gives me 08-Jan-2019 ! why is this happening ??
i have another question ! i have a time in this format 190608.347009447 - 'yymmdd.ffffffff', 'ffffffff' is the fractional part of the day.
to read this i am using this code !
inputtime = '190608.347009447';
jday = inputtime(1:6);
date(i) = datetime(jday, 'InputFormat', 'yyMMDD') + days(mod(str2double(inputtime), 1))
it gives me an error !!

채택된 답변

Ananthi Jegan
Ananthi Jegan 2020년 11월 19일
편집: Ananthi Jegan 2020년 11월 19일
For your first question, you have to use the InputFormat as 'yyMMdd' instead of 'yyMMDD'
datetime(jday,'InputFormat','yyMMdd')
Changing the above InputFormat also helps in correcting the second error as well; and to get the datetime including time values as follows
inputtime = '190608.347009447';
jday = inputtime(1:6);
datetime(jday, 'InputFormat', 'yyMMdd') + days(mod(str2double(inputtime), 1))
I hope this helps to correct the errors and to get the results as expected.
  댓글 수: 1
pruth
pruth 2020년 11월 19일
yes sir, it worked perfectly ! thank you !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by