I would like to have a live countdown to Christmas displayed on a GUI, in each player’s local time. The function I have running currently to find this is as follows:
local christmas = os.time({year = 2021, month = 12, day = 24, hour = 24, min = 0, sec = 0})
local function updateCountdown()
local localTime = os.time(os.date("*t"))
local difference = christmas - localTime
local secondsUntil = os.difftime(christmas,os.time())
local data = os.date("*t",secondsUntil)
countdown.Text = string.format("%i days, %i hours, %i minutes and %i seconds until Christmas!",data.day,data.hour,data.min,data.sec)
end
-- I also have a loop running this function every second.
I am running into two problems:
-
The time displayed in the game versus the time displayed on a website counting down to Christmas is one day out. This can be fixed by reducing the “day” in the
christmas
variable to 23, but I’m unsure as to why it’s actually happening in the first place. -
The time until the event does not display in the player’s local time. For me, it is shown in my local time, however, when I ask a person in a timezone 5 hours behind me to test, the time difference shows. My timezone is GMT.
I am particularly interested in solving problem #2, as I would like the countdown to display the correct amount of time until the date based on the player’s local time. Also, if there are better ways of programming this, I will take this on board.
Thanks.