How do I convert a decimal number to a time?

34 ビュー (過去 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?
Walter Roberson
Walter Roberson 2019 年 9 月 14 日

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by