?
Solved

Time Conversion

Posted on 1999-12-30
2
Medium Priority
?
129 Views
Last Modified: 2010-04-06
I want to convert a number, like 274, into minutes and seconds.

The output should be 4:34

Thanks


0
Comment
Question by:mdlittle
2 Comments
 
LVL 2

Accepted Solution

by:
hubdog earned 800 total points
ID: 2316269
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
 
LVL 20

Expert Comment

by:Madshi
ID: 2316293
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses
Course of the Month6 days, 4 hours left to enroll

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question