How do I convert a decimal number to a time?

31 visualizaciones (últimos 30 días)
Liam Quantrill
Liam Quantrill el 2 de Ag. de 2018
Comentada: Walter Roberson el 14 de Sept. de 2019
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 comentarios
jonas
jonas el 2 de Ag. de 2018
Well, that depends on the unit of 7.6342
Liam Quantrill
Liam Quantrill el 2 de Ag. de 2018
Hi jonas, sorry yeah I forgot to mention that, I was updating my question as you replied hahah

Iniciar sesión para comentar.

Respuesta aceptada

jonas
jonas el 2 de Ag. de 2018
Editada: jonas el 2 de Ag. de 2018
Alternatively, if you just want to display amount of hours and minutes.
duration(hours(7.8),'format','hh:mm')
ans =
duration
07:48
  5 comentarios
ameena sorour
ameena sorour el 14 de Sept. de 2019
If I want the opisite from 07:48 to 7.8?

Iniciar sesión para comentar.

Más respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 2 de Ag. de 2018
Editada: KALYAN ACHARJYA el 2 de Ag. de 2018
datestr(hours(7.8),'HH:MM');
Result
>> datestr(hours(7.8),'HH:MM')
ans =
07:48
  4 comentarios
Sean de Wolski
Sean de Wolski el 2 de Ag. de 2018
Editada: Sean de Wolski el 2 de Ag. de 2018
This is the old way to to it (before R2014b). In more recent releases, the duration approach is better.
KALYAN ACHARJYA
KALYAN ACHARJYA el 2 de Ag. de 2018
Thanks for the information.

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by