Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-06

Converting from seconds to TTime: easiest way?

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Morning list,

I'm trying to convert a large number of seconds to a TTime.

To my surprise - without a Delphi background ;) - EncodeTime only takes up to 59 seconds... ;)
Same for EncodeTimeInterval

So I ended up with something like:

IncSecond(EncodeTime(0,0,0,0), HugeNumberOfSecondsInteger);

is this the best way to do this or is there some smarter way I've missed?

Thanks,
Reinier

Reply by email

OBones
to Reinier Olislagers
Reinier Olislagers wrote 7 lines
Morning list, I'm trying to convert a large number of seconds to a TTime. To my surprise - without a Delphi background ;) - EncodeTime only takes up to 59 seconds... ;) Same for EncodeTimeInterval

Considering that TTime is a float where the fractional part is the part of a day, I would do it like this:

MyTTime := HugeNumberOfSecondsInteger / (24 * 60 * 60);

There might even be a constant somewhere called SecondsPerDay that would save you the writing of the denominator.

Reply by email

Unknown author
to Reinier Olislagers: I'm trying to convert a large number of seconds to a TTime. To my surprise - without a…
Try
MyTTime := HugeNumberOfSecondsInteger / (3600 * 24);
Reinier Olislagers wrote
Morning list, I'm trying to

convert a large number of seconds to a TTime.

To my surprise -

without a Delphi background ;) - EncodeTime only takes

up to 59

seconds... ;)

Same for EncodeTimeInterval So I ended up with

something like:

IncSecond(EncodeTime(0,0,0,0),
HugeNumberOfSecondsInteger);
is this the best way to do this or is

there some smarter way I've missed?

Thanks, Reinier

Reply by email

Reinier Olislagers
to Unknown author
Show quoted text 6 lines
Try MyTTime := HugeNumberOfSecondsInteger / (3600 * 24);

Bedankt, Darius.

That's indeed shorter and fairly clear... but the advantage of the other way is that I don't need to remember what units TTime uses internally... ;)

Regards,
Reinier

Reply by email

Sven Barth
to Reinier Olislagers
Reinier Olislagers wrote 11 lines
On 20-6-2012 11:53, wrote: > Try > > > > MyTTime := HugeNumberOfSecondsInteger / (3600 * 24); > Bedankt, Darius. That's indeed shorter and fairly clear... but the advantage of the other way is that I don't need to remember what units TTime uses internally... ;)

You could rely on constants provided by the "dateutils" unit (I'm rather sure that we'd provide approbiate replacements if we'd change the TDateTime type somewhen ;) ):

MyTTime := HugeNumberOfSecondsInteger * OneSecond;

Regards,
Sven

Reply by email

Reinier Olislagers
to Sven Barth: You could rely on constants provided by the "dateutils" unit (I'm rather sure that we'd…
Sven Barth wrote 13 lines
Am 20.06.2012 12:16, schrieb Reinier Olislagers: > On 20-6-2012 11:53, wrote: >> MyTTime := HugeNumberOfSecondsInteger / (3600 * 24); >> > Bedankt, Darius. > > That's indeed shorter and fairly clear... but the advantage of the other > way is that I don't need to remember what units TTime uses > internally... ;) You could rely on constants provided by the "dateutils" unit (I'm rather sure that we'd provide approbiate replacements if we'd change the TDateTime type somewhen ;) ):

Good point ;)

MyTTime := HugeNumberOfSecondsInteger * OneSecond;

Thanks.

Reply by email