[fpc-pascal] Efficient millisecond timestamp

Michael Van Canneyt michael at freepascal.org
Fri Jan 10 11:04:21 CET 2014



On Fri, 10 Jan 2014, Mark Morgan Lloyd wrote:

> Michael Van Canneyt wrote:
>> On Fri, 10 Jan 2014, Mark Morgan Lloyd wrote:
>> 
>>> What's the most efficient and portable way of getting a millisecond 
>>> timestamp, relative to any ancient epoch? I find
>>> 
>>> TimeStampToMSecs(DateTimeToTimeStamp(Now))
>>> 
>>> hard to swallow since Now() is hardly efficient and the resulting Comp is 
>>> marked as non-potable in the documentation.
>> 
>> Where does it say that ?
>
> http://www.freepascal.org/docs-html/prog/progsu157.html#x200-2050008.2.5 "On 
> other processors, the comp type is not supported."
>
>> And why do you think now returns a comp ? It returns a double.
>
> http://lazarus-ccr.sourceforge.net/docs/rtl/sysutils/timestamptomsecs.html 
> returns comp.

Yes, my bad, I was referring to "Now".

>
> And I hardly see the point of converting something coming from the hardware 
> and/or a kernel counter to a double and then back to a quadword.

Nevertheless, Now() is the only portable construct available. 
Multiply it with msecsperday and round to int64 if you need an integer value.

Michael.



More information about the fpc-pascal mailing list