Time Conversion

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

The output should be 4:34

Thanks


mdlittleAsked:
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.

hubdogCommented:
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.

Start your 7-day free trial
MadshiCommented:
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;

Regards, Madshi.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.