How do I convert a decimal number to a time?

조회 수: 32 (최근 30일)
Liam Quantrill
Liam Quantrill 2018년 8월 2일
댓글: Walter Roberson 2019년 9월 14일
How would I convert a number such as 7.8 into a time in HH:MM? 7.8 is 7.8 hours from the start of the day, so should be shown as 07:48.
  댓글 수: 2
jonas
jonas 2018년 8월 2일
Well, that depends on the unit of 7.6342
Liam Quantrill
Liam Quantrill 2018년 8월 2일
Hi jonas, sorry yeah I forgot to mention that, I was updating my question as you replied hahah

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

채택된 답변

jonas
jonas 2018년 8월 2일
편집: jonas 2018년 8월 2일
Alternatively, if you just want to display amount of hours and minutes.
duration(hours(7.8),'format','hh:mm')
ans =
duration
07:48
  댓글 수: 5
ameena sorour
ameena sorour 2019년 9월 14일
If I want the opisite from 07:48 to 7.8?

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

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 8월 2일
편집: KALYAN ACHARJYA 2018년 8월 2일
datestr(hours(7.8),'HH:MM');
Result
>> datestr(hours(7.8),'HH:MM')
ans =
07:48
  댓글 수: 4
Sean de Wolski
Sean de Wolski 2018년 8월 2일
편집: Sean de Wolski 2018년 8월 2일
This is the old way to to it (before R2014b). In more recent releases, the duration approach is better.
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 8월 2일
Thanks for the information.

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by