Anyway to abbreviate roblox time?

I have a time Gui, but was wondering if there was anyway to abbreviate the roblox time which means changing it to the AM, PM Format instead of Military Time like 16:00?

I think Jailbreak does this somehow.

Script for changing the gui to the time.

while true do

script.Parent.Text = string.sub(game.Lighting.TimeOfDay,1,5)

wait()

end

2 Likes

You could change the first 2 characters into a number then find the remainder when divided by 12.

script.Parent.Text = tonumber(string.sub(game.Lighting.TimeOfDay,1,2))%12 .. string.sub(game.Lighting.TimeOfDay,3,5)

This would leave you with a small issue though. When it’s noon it will show up as 0:00. You could fix that by subtracting one before taking the remainder, then adding one back.

script.Parent.Text = (tonumber(string.sub(game.Lighting.TimeOfDay,1,2))-1)%12+1 .. string.sub(game.Lighting.TimeOfDay,3,5)

To find out if it’s AM or PM using this math approach you would divide by 12 then check if it’s less than 1 for AM otherwise it’s PM. Additionally you could use lists to look it up, or just if statements.

3 Likes

Look into Lighting.ClockTime instead. You don’t have to do string manipulation with this property.

local clockTime = game:GetService("Lighting").ClockTime
local hour = math.floor(clockTime) % 12
local minute = math.floor((clockTime - math.floor(clockTime)) * 60)
local isPM = clockTime >= 12

local timeString = ("%02i:%02i %s"):format(hour, minute, isPM and "PM" or "AM")
7 Likes