Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I print os.time?

Asked by
262187 45
8 years ago

How do I print os.time using the format Hours:Minutes ?

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

Normal Lua has a function os.date to format times. Unfortunately, ROBLOX lacks this function.

You can use a ModuleScript that someone else has written to do this for you (there are a few, I've made on here).

While date-time is fairly problematic, just hours and minutes isn't so bad.

In Unix time, every day has precisely 86400 seconds in it; a minute has precisely 60 seconds and an hour has precisely 60 minutes.

Then

local now = os.clock() -- in seconds
local second = now % 60
now = (now - second)/60 -- in minutes
local minute = now % 60
now = (now - minute)/60 -- in hours

if minute < 10 then
    print(hour .. ":0" .. minute)
else
    print(hour .. ":" .. minute)
end
0
So just run this in a Local Script or a regular script? 262187 45 — 8y
0
Either, it doesn't matter. You can only completely trust that os.time() is UTC time on a server, though (though on a normal client it will be UTC) BlueTaslem 18071 — 8y
Ad

Answer this question