How to make show am and pm?

This is a ingame clock tex label shower.

It shows the time in game!

But how to I make it show am and pm?

while true do
	local Hours  = math.floor(game.Lighting:GetMinutesAfterMidnight()/60) --round hours 
	local Minutes = math.floor(game.Lighting:GetMinutesAfterMidnight() - (Hours * 60)) --take the amount of minutes already accounted for with the hours, then use that to get the minutes
	if Hours > 12 then
		Hours = Hours - 12
	end
	if Minutes < 10 then
		Minutes = "0"..Minutes
	end
	script.Parent.Text = "⏰: "..Hours..":"..Minutes
	wait()
end
1 Like

In simple ways you can make it AM by default and if the hours is greater than 12 it’s set to PM via variable.

Also you can use a formatted string which allows for zeros padding

while true do
	local Hours  = math.floor(game.Lighting:GetMinutesAfterMidnight()/60) --round hours 
	local Minutes = math.floor(game.Lighting:GetMinutesAfterMidnight() - (Hours * 60)) --take the amount of minutes already accounted for with the hours, then use that to get the minutes
	local timeThing = "AM"
	if Hours > 12 then
		timeThing = "PM"
		Hours -= 12
	end
	script.Parent.Text = string.format("⏰: %d:%02d%s",Hours,Minutes,timeThing)
	wait()
end

This will format the string accordingly using the hours, minutes with a zero padded if less than 10, and the timeThing

You can probably look up how exactly AM and PM works as this is just a barebones addition

String formatting guide
How to properly convert 24 hour to 12 hour with Am and Pm

@thatrandomnoob23 You could’ve just sent me a message or mentioned me in the post as it’s kind aoff-topic

3 Likes

Why and What is this? Just asking

1 Like

It’s a format string

string.format("⏰: %d:%02d%s",Hours,Minutes,timeThing)

Basically means, put the amount of hours as %d, put the amount of minutes in %02d and add zeroes when needed, and add AM or PM in %s

The link I sent should give you a bit more information about it

2 Likes