Determining a Player's Time Zone

Is there any possible way to determine a players actual time zone using a method other than asking?

You have to do this based on time values. The easiest way is probably for the client to send its os.time() value to the server and for the server to compare that with its own os.time() value, dividing that by 3600, and rounding it to the nearest timezone hour offset from UTC+0. Keep in mind this will always be an estimate because you cannot know whether the time settings of the client’s device are entirely correct.

Do you have a particular use case for wanting to estimate the time zone?

8 Likes

I was going to use it to determine when a given day started or ended for a player.

Then the method above should work for server-side. If you need to know entirely client-sided which day it is, os.date will do the trick (returns components of the current date) and you won’t need to communicate with the server at all then.

3 Likes

@Crazyman32 has a great system here that’s available for people to take and use. It grabs the local timezone as well.

1 Like

I wouldn’t recommend using this, it’s from 2012 and before os.date was added. os.date is infinitely more user friendly. os.date("*t") will return a table of all the information you need to know about the local timezone.

8 Likes

I have an updated Date module that uses the new os function. It’s modeled after the JavaScript Date object

6 Likes