Countdown is 12 hours behind

So I’m trying to make a countdown that counts down to a specific time, but adapts to each timezone. For example if you’re in central US time, it counts down to midnight on Dec. 25th, 2020 CST. But if you’re in eastern US time, it reaches the end an hour earlier than it does for the CST players.

I have it set up to print to test it, but the time printed is 12 hours slower than what it should be. I’m in CST, so that’s what timezone the countdown should currently be using. I’m using Christmas to test this because there’s plenty of easily available countdowns online to check if I’m getting the correct time. Here’s a picture of where my countdown should be (the christmas countdown) vs what I’m getting in output:

I’m using a local script in StarterGui, once it’s functional I’ll make it display the time with a Gui. Here’s what I have in the script:

local RunService = game:GetService("RunService")

local targetTime = os.time({year = 2020, month = 12, day = 24, hour = 24, min = 0, sec = 0})

RunService.Heartbeat:Connect( function()
	local diffSeconds = targetTime - os.time()
	local countdown ='*t', diffSeconds)
	if diffSeconds <= 0 then
		print("Christmas has arrived")
		print(('there are %i days, %i hours, %i minutes, and %i seconds until 12:00am on Christmas!'):format(countdown.yday, countdown.hour, countdown.min, countdown.sec))

1 Like

When I did something like this, I had to set the hour back further than it should be. Try setting the hour 12 hours back.


Try using !*t for your format string, the timestamp the server is sending is probably a UTC timestamp.


Doing that just threw it off even further. When I use *t it’s 12 hours behind, when I used !*t it’s 18 hours behind.

1 Like

have you tried setting the hour to 0?

1 Like
local targetTime = os.time({year = 2020, month = 12, day = 24, hour = 24, min = 0, sec = 0})

while true do
	localTime = os.time("*t"))
	difference = targetTime-localTime

Try this, it should print true when Christmas arrives in your time zone.

1 Like

Yes, I originally had the day at 25 and the hour at 0, that was 12 hours off so then I tried the 24th with the hour at 24.

1 Like

Thanks, that worked.
It’s weird that it has to be set back further, I figured I’d written something wrong.

1 Like

didn’t think of this for some reason but change this to

local diffSeconds = targetTime - tick()