필터 지우기
필터 지우기

Fraction of a day to HH:MM:SS

조회 수: 17 (최근 30일)
Charlie Wood
Charlie Wood 2017년 2월 9일
댓글: Charlie Wood 2017년 2월 9일
Good day everyone.
I have a date, 17037.46688591, and want to convert it to a datetime.
I'm not sure what to include in the datetime InputFormat to allow for the fraction of a day to get the HH:MM:SS.
I can get the date:
inputdate = '17037.46688591';
jday = inputdate(1:5);
date = datetime(jday,'InputFormat','yyDDD')
date = 06-Feb-2017
How do I get .46688591 into HH:MM:SS?
I've tried a few things but I must be doing something wrong. Thanks for the help.

채택된 답변

Guillaume
Guillaume 2017년 2월 9일
This would work:
inputdate = '17037.46688591';
jday = inputdate(1:5);
date = datetime(jday, 'InputFormat', 'yyDDD') + days(mod(str2double(inputdate), 1))
assuming that .46688591 is a fraction of a day.
  댓글 수: 1
Charlie Wood
Charlie Wood 2017년 2월 9일
Awesome, thank you. Answer came out exactly as needed. Didn't think to just use days() to turn it into a duration. I think I need more coffee/practice. Thanks again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by