How do I convert or code so from a given input of 658 I get the clock time of 6:58. So that it would be something like this:
Input time based on a 24-hour clock: 658
You entered 6:58
The equivalent time based on a 12-hour clock is 6:58 AM

댓글 수: 2

Walter Roberson
Walter Roberson 2020년 3월 28일
See mod()
Amplifying on Walter's hint...
timestr=@(n) sprintf('Clock time: %2d:%02d',fix(n/100),mod(n,100));
>> timestr(658)
ans =
'Clock time: 6:58'
>>
Salt to taste...

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

 채택된 답변

SaiDileep Kola
SaiDileep Kola 2020년 3월 31일
편집: dpb 2020년 3월 31일

0 개 추천

In addition to the hints given, this would entirely solve your problem
function Time = findclocktime(I)
flag = 'am';
if(I >= 1300)
I = I - 1200;
flag = 'pm';
end
Time = sprintf('Clock time: %2d:%02d %s',fix(I/100),mod(I,100),flag);
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2020년 3월 28일

편집:

dpb
2020년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by