The wiki doesn't help me too much and the forums are filled with the wrong type of people, so I resorted into coming here.
I'm working on a daily rewards system and I hear you use os.time(), but I don't understand what os.time() does.
os.time() always returns Unix time. If you are unsure what Unix time is, Unix time is defined as the number of seconds that have passed since 00:00:00 Coordinated Universal Time, Thursday, 1 January 1970.
Since tick()
always returns what the users local time is, it is an inefficient way to keep track of time over multiple servers. The best thing to do is use os.time()
which chooses one timezone [Unix (which is equivalent to GMT)] and records that. This way you can keep the standard of keeping time universal for all players.
If you want to see a neat trick to figure out a timezone, take the difference between the local users time, and os.time()
and compare with a list:
print(os.difftime(tick(),os.time())/3600)
For me, since I am in Eastern Timezone
which is also GMT -04:00
, the result that got printed was -4. Using this, you can try and guess what timezone the player is in with a list such as:
So I'm assuming you know about tick(), which comes with the following warning on the wiki:
Warning: tick() returns local time, and time zones between servers may vary. A reliable option to get the same time on every server is to call os.time().
Basically, it's a method of getting the time, except os.time() can be used as a standard time, as each machine and server could potentially return different numbers for tick() because of time zone differences.
os.time() is like tick(), except it is the same no matter which device it is called on.
More information here