#1 2020-03-02 08:42:55

Greg0r
Member
Registered: 2019-01-28
Posts: 49

Current time in miliseconds or more precise

Guys,

Can you help with making time based uuid(timestamp)?
Very quick comes to my mind curtime:=FloatToStr(Now);
But maybe there is something more precise? As result some Int64 will be good.
Maybe mORMot could help there?

Last edited by Greg0r (2020-03-02 08:43:17)

Offline

#2 2020-03-02 08:55:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Current time in miliseconds or more precise

Check UnixMSTimeUTC() function to retrieve the time as such.
See https://synopse.info/files/html/api-1.1 … XMSTIMEUTC

And check TSynUniqueIdentifier/TSynUniqueIdentifierGenerator which purpose is to create 64-bit UUID even spread on over several systems (up to 65536 generation points).
See https://synopse.info/files/html/api-1.1 … IDENTIFIER

Offline

#3 2020-03-02 09:38:25

Greg0r
Member
Registered: 2019-01-28
Posts: 49

Re: Current time in miliseconds or more precise

@ab, thx
I'm after lecture of https://www.thedelphigeek.com/2007/10/c … urate.html
I did not imagined before how not accurate are std functions.

Solutions from your framework looks good.
Can you provide shortest simplest usage of your functions to get current time in XXXXXXXXXXXXX int64?
UnixMSTimeUTC() function and  TSynUniqueIdentifier/TSynUniqueIdentifierGenerator

Last edited by Greg0r (2020-03-02 10:13:27)

Offline

#4 2020-03-02 10:33:16

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Current time in miliseconds or more precise

Just call UnixMSTimeUTC().
Under Windows, it calls GetSystemTimeAsFileTime() which has true ms resolution.
Under Linux, it will call the fast clock_gettime(CLOCK_REALTIME_COARSE) if available.

See https://docs.microsoft.com/en-us/window … ime-stamps for some official information from Microsoft.

Offline

#5 2020-03-02 10:52:10

Greg0r
Member
Registered: 2019-01-28
Posts: 49

Re: Current time in miliseconds or more precise

Thank you

Offline

#6 2020-03-02 11:39:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Current time in miliseconds or more precise

After more research, I found http://www.windowstimestamp.com/description

It appears that GetSystemTimeAsFileTime() doesn't have true ms resolution, but only follows the HW timer interrupt, which may be around 10-16 ms.
On Windows 8+, UnixMSTimeUTC() will use https://docs.microsoft.com/en-us/window … asfiletime which is slightly slower, but has true ms resolution.
Please check https://synopse.info/fossil/info/9a8e9b23ad

Offline

#7 2020-03-02 15:41:34

Greg0r
Member
Registered: 2019-01-28
Posts: 49

Re: Current time in miliseconds or more precise

cool

Offline

Board footer

Powered by FluxBB