How do you format os.clock into 00:00:00?

Hello! I have a timer that uses os.clock(), and I want to know how I can format it into hours, seconds, and milliseconds. If you do know please reply. Thank you!

Then try this

print(os.date("%Y%m%d %H:%M:%S"))

You can learn more about that in this lua document which also apply to roblox Programming in Lua : 22.1 (I just read the title and you weren’t talking about getting the real date my bad here is one formatting os.clock into 00:00:00)

--This will only set it to exactly 00:00:00
print(os.date("%X",0))
--This will set the current time in your timezone
print(os.date("%X"))
2 Likes

Hours is the integer part of seconds / 3600
Minutes is the integer part of the remaining seconds / 60
Seconds is the remainder of that

1 Like

You may want to look into using DateTime to format strings

local timestamp = DateTime.fromUnixTimestamp(os.clock())
local formattedTimestamp = timestamp:FormatUniversalTime("HH:mm:ss", "en-us"))
print(formattedTimestamp)

More information on the date time string formatting can be found here: DateTime | Documentation - Roblox Creator Hub

To include hours, minutes, seconds, and milliseconds:

local timestamp = DateTime.fromUnixTimestamp(os.clock())
local formattedTimestamp = timestamp:FormatUniversalTime("HH:mm:ss:SS", "en-us"))
print(formattedTimestamp)
5 Likes