How do I convert a decimal number to a time?

34 次查看(过去 30 天)
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 个评论
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 个评论

请先登录,再进行评论。

更多回答(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.

请先登录,再进行评论。

类别

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