# Time Conversion

I want to convert a number, like 274, into minutes and seconds.

The output should be 4:34

Thanks

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I can not understand what you mean very well.Below is a demo may be useful for you.

var
Timestr:String;
datetime:TDateTime;
begin
TimeStr:=inttostr(274 div 60) +':'+inttostr(274 mod 60);//get a string 4:34
datetime:=strtotime(Timestr);
end;

good luck

hubdog
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Yep, hubdog is right.

Here comes the function I'm using for such stuff:

// Converts "time" to a string.
// Examples:
// 15          ->  '15 ms'
// 1100        ->  '1:10 s'
// 61*1000     ->  '1:01 min'
// 61*60*1000  ->  '1:01 h'
function MsToStr(time: cardinal) : string;
begin
if time >= 1000 then begin
if time >= 1000 * 60 then begin
if time >= 1000 * 60 * 60 then begin
time := time div (1000 * 60);
result := IntToStr(time mod 60);
if Length(result) = 1 then result := '0' + result;
result := IntToStr(time div 60) + ':' + result + ' h';
end else begin
time := time div 1000;
result := IntToStr(time mod 60);
if Length(result) = 1 then result := '0' + result;
result := IntToStr(time div 60) + ':' + result + ' min';
end;
end else begin
result := IntToStr(time mod 1000 div 10);
if Length(result) = 1 then result := '0' + result;
result := IntToStr(time div 1000) + ',' + result + ' s';
end;
end else result := IntToStr(time) + ' ms';
end;