Issues with os.time()

Hey developers,

So I’m having an issue with my countdown clock code where it appears to put the local time zone instead of the UTC time. This is VERY bad as it suggests that the time zone is changing based on server location. Is this true, because if it is, its going to screw up my entire live event.

This is the code that is displaying my local time apparently: local timetoreach = os.time({year = 2022, month = 7, day = 20, hour = 12, min = 0, sec = 0})

Has anyone else faced this issue or know if its actually an issue?

1 Like
local enabled = false

while true do
	wait(1)
	local Time = os.time()
	local Year = os.date("!*t",Time)["year"]
	local Month = os.date("!*t",Time)["month"]
	local Day = os.date("!*t",Time)["day"]
	local Hour = os.date("!*t",Time)["hour"]
	local Min = os.date("!*t",Time)["min"]
	local Sec = os.date("!*t",Time)["sec"]
	
	local t1 = os.time({year=Year,month=Month,day=Day,hour=Hour,min=Min,sec=Sec})
	local t2 = os.time({year=2022,month=7,day=20,hour=12,min=00,sec=0})
	
	local date = os.difftime(t1,t2)/-1
	if enabled == false then
		script.Parent.SurfaceGui.TextLabel.Text = string.format("%02i:%02i:%02i", date/60^2, date/60%60, date%60)
	end
	if script.Parent.SurfaceGui.TextLabel.Text == "-1:00:00:000" then
		enabled = true
		script.Parent.SurfaceGui.TextLabel.Text = "00:00:00:000"
		script.Parent.SurfaceGui.TextLabel.TextColor3 = Color3.new(255,0,0)
		wait(0.5)
		script.Parent.SurfaceGui.TextLabel.TextColor3 = Color3.new(255,255,255)
		wait(0.5)
		script.Parent.SurfaceGui.TextLabel.TextColor3 = Color3.new(255,0,0)
		wait(0.5)
		script.Parent.SurfaceGui.TextLabel.TextColor3 = Color3.new(255,255,255)
		wait(0.5)
		script.Parent.SurfaceGui.TextLabel.TextColor3 = Color3.new(255,0,0)
		wait(0.5)
		script.Parent.SurfaceGui.TextLabel.TextColor3 = Color3.new(255,255,255)
		wait(0.5)
		script.Parent.SurfaceGui.TextLabel.Visible = false
	end
end
1 Like

I did end up debugging the issue on my own, it was due to roblox studio’s registration of os.time

Studio displays local time for os.time, roblox clients display UTC. This is a very annoying system

1 Like