Is there any real difference between os.time() and tick()?

Its pretty self explanatory.

Is there any real difference between os.time() and tick()?

Thing is when i run this code:

print(tick() ..  " / " .. os.time()) 

The results between tick and os.time are pretty similar.

image

The only noticeable difference is that tick has decimals.

Is there more i should know about these two functions?

3 Likes

tick uses the current time zone.

image

If you look at your image, os.time and tick are actually returning two different nubmers.

tick being the seconds since EPOCH in your time zone, os.time returning Unix time since EPOCH.

2 Likes

tick() gets the amount of seconds (+ milliseconds) from 1/1/1970 but in local time.

os.time() only gets the seconds (not milliseconds) from the same date but in UTC time.

Roblox engineers have plans to deprecate tick()

10 Likes

I’m starting a function to store possible game errors in a DataStore to later analyze them and fix bugs.
For that, I’m using LogService.MessageOut
I need to store the time when the error occurred, exactly as it is shown in the Console today, ie plus milliseconds.
os.time() does not show milliseconds.
os.clock() is not based on the UNIX epoch.
tick() would then be the only viable solution, similar to os.time() but including milliseconds.
But they are saying that tick() will be deprecated.
So what’s the solution to storing UNIX epoch with milliseconds?

2 Likes

DateTime, specifically DateTime.now(), gives the number of milliseconds since the UNIX epoch and already takes into account for times zones (so it’s in GMT time).

2 Likes