When designing displays and other user experience enhancements, it can be beneficial to appeal to a timezone better suited to your audience. While by default we’re only able to use the os.time function which returns the UTC time, we can easily use this to find other timezones.
To do this, just find the offset between the desired timezone and UTC time and apply the difference(in seconds) to the UTC. Below you can find an example of getting the current time in EST.
local UTCSeconds = os.time()
local SecondsInHour = 3600
local ESTSeconds = UTCSeconds - (SecondsInHour * 5) -- UTC is 5 hours ahead of EST, so take away 5 hours
local ESTDate = os.date("!*t", ESTSeconds)
local hourString = tostring(ESTDate.hour > 12 and ESTDate.hour % 12 or ESTDate.hour)
local minuteString = ESTDate.min < 10 and "0"..ESTDate.min or tostring(ESTDate.min)
local period = ESTDate.hour > 12 and "PM" or "AM"
print("The time is "..hourString..":"..minuteString.." "..period)
Something important to note is some timezones shift throughout the year, so it may be useful to adjust your offset based on what time of the year it is. This can easily be done using os.date.
The main purpose of this though was for the developer to maybe pick a timezone based on what region most of their players would be from. Ex: An american football game might want to display times in one or more of the timezones in the US
I see, I’m thinking of a larger scale usage of this feature and how it could expand; for example a Daily reward which tells you exactly when to come back in the player’s local time thus something like that would be more widely used.
I don’t think you should use the user’s local time when giving benefits such as daily rewards. What stops them from just spoofing their location or time? Things such as daily rewards should always be based off a centralized timezone.
I made a mini tutorial like this in a support thread before, but the issue with this is that Eastern Time breaks into two: Standard and Daylight. This code doesn’t suffice once we’re in EDT. From the client you are able to check if DST is active but not from the server, so you can’t natively automate a switch between timezones.
Ideas that don’t extend towards using a third party service?
I am sorry for responding on such an old thread, but I am looking through these very interesting methods on improving a player’s game experience, and am wondering what the exact purpose of this would be? I know games like “Welcome to Bloxburg” uses time offsets, but what exactly can they be used for and how can they help?