Hi Folks,
Many mechanics in my game rely off knowing the amount of time that has passed since UNIX epoch. This is in order to manage cooldowns, and other time based events within my game. For these features, it’s extremely important that I have an accurate, and consistent indicator, of how long ago the UNIX epoch was, and that clients and the server theoretically give the same value if called at the same time.
Currently, I’m running into a few problems.
1. Timezone Interference
The closest functionality that ROBLOX provides for my problem is tick(). This works perfectly on the server with no problems. However, upon using tick() on the client, it seems that time zones aren’t accounted for, taking away or adding to the result of tick() depending on how much they deviate from UTC. In order to manage these time zone issues, this leads me to my 2nd problem:
2. Decimal Accuracy
It’s important that a solution to my problem has at least a few decimal places accuracy, ideally millisecond precision. This is provided by tick(), but I cannot use it due to the reasons mentioned above. A solution to avoiding time zone interference is to use os.time(), however, this only returns an integer, and does not return the decimal places that I need to have accurate timers.
print(os.time()) --> 1687702060
print(tick()) --> 1687702064.9734404
I’ve tried using some sort of Frankenstein method, where I combine the time zone traits of os.time() and the decimal accuracy of tick() (shown below), but as shown in the snippet above, these two values do not line up, deviate from each other by about 4 seconds or so, which makes appending the decimal places of tick() to os.time() a fruitless endeavour.
function UnixNow()
return os.time() + (tick() % 1) - 1
end
tl;dr, is there a way to get the number of milliseconds since January 1st 1970 00:00:00 UTC? Or if not, what hacks can I use to achieve a similar outcome?
Thanks,
xeavz