How would I get unix timestamp with (preferably) millisecond precision?

I’m basically looking for a high-precision version os.time() to get a number more precise than the second.

I’ve come up with a solution using tick() and modulo, adding the “offset” returned from tick % 1 to os.time but I’m unsure as to whether this is a good solution or not, ideally I wouldn’t have to rely on two functions and I’d just use some built-in one. Here’s what I have:

local timeOffset = tick() % 1 
local precise = os.time() + timeOffset 
print('\n',os.time(),'\n', precise)

But yeah, thanks for any help!

2 Likes

June 22, 2022, midnight, UTC
In seconds, as a float.
DateTime.fromUniversalTime(2022, 6, 22, 0, 0, 0, 0).UnixTimestampMillis/1000

Now, in seconds, as a float.
DateTime.now().UnixTimestampMillis/1000

3 Likes

Second one is what I’m looking for, thanks! I didn’t know about that function.

2 Likes

Yeah, I just found it recently myself. It’s been very helpful.

2 Likes