How can I make a countdown timer but in hours and minutes?

I want an event countdown that counts down minutes and hours till the date (July 1st). I currently only know how to make it countdown seconds.

How can I use os.time() to make it countdown hours and minutes?

I have read the os.time document but I can’t figure it out. :man_shrugging:

My current code

local timeToStart = 1623712500
local timeToEnd = 1625144400
local timeLeft = game.Workspace.Billboard.Timeee.TimeLeft.Time

function liveEvent()
	timeLeft.Text = "Countdown till release starting!!!"
end

while wait(1) do
	local timeNow = os.time()
	
	if timeNow >= timeToEnd then
		break
	end
	
	if timeNow >= timeToStart then
		print("Starting the live event!")
		liveEvent()
		break
	else
		print("Time till live event: "..(timeToStart-timeNow).." seconds")
		timeLeft.Text = (timeToStart-timeNow).."!"
	end
end


while wait(1) do
	local timeNow = os.time()
	
	if timeNow <= timeToEnd then
		timeLeft.Text = (timeToEnd-timeNow).." seconds till release."
	end
end

Does anybody know and can help me?

1 Like

Here is a function that will turn seconds to hours and minutes.

function ConvertSeconds(seconds)

return math.floor(seconds/3600),math.floor(seconds%3600)

end

-- example:

local hours, minutes = ConvertSeconds(3600)

print(hours,minutes)

The problem has been solved by this post and solution! Thank you @ReturnedTrue

How do I make a live countdown