How to make a formatted clock (12:00 p.m.)

I would like to make a clock like the one in Brookhaven RP. I could simply have a textlabel display the clock time from lighting but I would like it to be formatted like, 10:00 or 9:30 and not 21:00. Does anyone know how to do this? I have only seen tutorials for local clocks.

-thanks, Zompocolypse

Edit#1:
Could this post be helpful?

9 Likes

See if this works:

local Gui = --Put your gui here

function getLightingTime()
	local totalMinutes = game.Lighting:GetMinutesAfterMidnight()
	local hours = math.floor(totalMinutes / 60)
	local minutes = math.floor(totalMinutes % 60)
	local period
	if hours < 12 then
		period = "AM"
	else
		period = "PM"
		hours -= 12
	end
	if hours == 0 then
		hours = 12
	end
	return string.format("%02d:%02d %s", hours, minutes, period)
end

while true do
	Gui.Text = getLightingTime()
	wait()
end
13 Likes

This is a local script, correct?

1 Like

I have mine in a script, but I think it should work in a local script.

2 Likes

How did you learn the % things and how to do that?

% is modulo. It returns the remainder of division. Think 10/5 = 2. 5 fits into 10 perfectly so the remainder is 0 or 10%5 = 0

2 Likes