Os Time formatting help

local function getTime()
    local date = os.date("*t")
    return ("%02d:%02d"):format(((date.hour % 24) - 1) % 12 + 1, date.min)
end

local lightningTime = game.Lighting.TimeOfDay
while wait(1) do
	print(getTime())
	lightningTime = getTime()
end

This only prints 12hr format i need to be 24hr format cause time of day is 00:00:00 like this any way to format it like this thank you!

os.date returns a time corresponding to the 24 hour clock to begin with, so why add unnecessary operations?

local function getTime()
	date = os.date("*t") 
	return ("%02d:%02d:%02d"):format(date.hour, date.min, date.sec)
end
2 Likes

do i just make the TimeOfDay to the formatted os.date

It’d be the same as your original code, only swapping out your getTime function for the one I included in my post.

1 Like

image

local function getTime()
	local date = os.date("*t") 
	return ("%02d:%02d:%02d"):format(date.hour, date.min, date.sec)
end

local lightningTime = game.Lighting.TimeOfDay
while wait(1) do
	print(getTime())
	lightningTime = getTime()
end

It doesn’t change the time?
The time is formatted like this: 20:39:05

local function getTime()
	local date = os.date("*t") 
	return ("%02d:%02d:%02d"):format(date.hour, date.min, date.sec)
end

while wait(1) do
	print(getTime())
	game:GetService("Lighting").TimeOfDay = getTime()
end

Basically just remove the variable lightingTime and replace it with the line I added mb*

2 Likes