Code: Select all

` WorkTime:=SystemFileTimeToDateTime(UpTime);`

AddContent(AResponse,'Up ' + IntToStr(Trunc(WorkTime)) + ' days ' + TimeToStr(WorkTime));

Thanks,

Mark

I'd like to do something similar to this, but starting with the UpTime being just the total number of seconds:

Thanks,

Mark

Code: Select all

` WorkTime:=SystemFileTimeToDateTime(UpTime);`

AddContent(AResponse,'Up ' + IntToStr(Trunc(WorkTime)) + ' days ' + TimeToStr(WorkTime));

Thanks,

Mark

mark wrote:I'd like to do something similar to this, but starting with the UpTime being just the total number of seconds:Code: Select all

`WorkTime:=SystemFileTimeToDateTime(UpTime);`

AddContent(AResponse,'Up ' + IntToStr(Trunc(WorkTime)) + ' days ' + TimeToStr(WorkTime));

Thanks,

Mark

Hi Mark,

I've reread your question several times but I am still not sure what the exact question is that you are asking.

There are a huge range of time functions available but to avoid guessing could you offer a little more clarification?

Thanks

Garry.

Ultibo.org | Make something amazing

https://ultibo.org

https://ultibo.org

I have a time in tenths of a second, and I want to convert it to something that can be processed by TimeToStr.Ultibo wrote:mark wrote:I'd like to do something similar to this, but starting with the UpTime being just the total number of seconds:Code: Select all

`WorkTime:=SystemFileTimeToDateTime(UpTime);`

AddContent(AResponse,'Up ' + IntToStr(Trunc(WorkTime)) + ' days ' + TimeToStr(WorkTime));

Thanks,

Mark

Hi Mark,

I've reread your question several times but I am still not sure what the exact question is that you are asking.

There are a huge range of time functions available but to avoid guessing could you offer a little more clarification?

Thanks

Garry.

mark wrote:I have a time in tenths of a second, and I want to convert it to something that can be processed by TimeToStr.

Thanks, that makes sense now.

The TDateTime format in Free Pascal (and Delphi) is a Double (a floating point value) with the integer part representing the date (as a number of days) and the fractional part representing the time.

Taking your case of tenths of a second, if you had a value of 150 that represents 15 seconds you would do something like this to convert it to a TDateTime for passing to TimeToStr().

Code: Select all

`var`

Seconds:LongWord;

DateTime:TDateTime;

begin

//Convert tenths of a second to seconds

Seconds:=150 div 10;

//Convert seconds to a TDateTime using the PASCAL_TIME_SECONDS_PER_DAY constant from GlobalConst

//(This is simply the number of seconds per day which is 86400 or 60 x 60 x 24)

DateTime:=((Seconds mod PASCAL_TIME_SECONDS_PER_DAY) / PASCAL_TIME_SECONDS_PER_DAY);

//Convert to a string

Value:=TimeToStr(DateTime);

And that would return 00:00:15

If your seconds value can contain more the one day then you can expand that slightly to save the number of days as well, like this:

Code: Select all

` //Convert seconds to TDateTime and store the number of whole days in the integer part`

DateTime:=(Seconds div PASCAL_TIME_SECONDS_PER_DAY) + ((Seconds mod PASCAL_TIME_SECONDS_PER_DAY) / PASCAL_TIME_SECONDS_PER_DAY);

//The number of days can then be extracted using Trunc()

Days:=Trunc(DateTime);

You can also shortcut and convert directly from tenths of a second but I'll leave that to you to try.

Ultibo.org | Make something amazing

https://ultibo.org

https://ultibo.org

Users browsing this forum: No registered users and 0 guests