How do I convert a decimal number to a time?
Show older comments
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 Comments
jonas
on 2 Aug 2018
Well, that depends on the unit of 7.6342
Liam Quantrill
on 2 Aug 2018
Accepted Answer
More Answers (1)
KALYAN ACHARJYA
on 2 Aug 2018
Edited: KALYAN ACHARJYA
on 2 Aug 2018
datestr(hours(7.8),'HH:MM');
Result
>> datestr(hours(7.8),'HH:MM')
ans =
07:48
4 Comments
Liam Quantrill
on 2 Aug 2018
KALYAN ACHARJYA
on 2 Aug 2018
Edited: KALYAN ACHARJYA
on 2 Aug 2018
Updated answer datestr(hours(7.8),'HH:MM');
Sean de Wolski
on 2 Aug 2018
Edited: Sean de Wolski
on 2 Aug 2018
This is the old way to to it (before R2014b). In more recent releases, the duration approach is better.
KALYAN ACHARJYA
on 2 Aug 2018
Thanks for the information.
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!