0

# Can someone explain os.time() to me? I'm so confuesed!

MattVSNNL 116
5 days ago

I've been seeing a Roblox game making a text that shows the real-time and week, And I dug a bit and figured out it's called os.time(), I looked on youtube a bit and found no videos that teach you how it works, So the only logical thing I figured to do was ask someone, So can anyone tell me how it works and maybe put an example about it? Thank you!

0
Its just basically a certain number of seconds from a time. You just convert it to minutes by dividing by 60. SImple MATH BMWLux 0 — 4d

0

os.time returns the number of seconds that have passed since 1st January 1970, also known in Computing as the UNIX Epoch.

os.time, rather than os.date is useful for making timers or stopwatches. For example, if I wanted to time how long it takes a player to press a button (in seconds) I could do something like this:

local Button = game.Workspace.Button

local start = os.time()
end)

Button.MouseClick:Connect(function()
local end = os.time()
local diff = end - start
print("You took "..diff.." seconds to press the button since you joined!")
end)


For the sake of brevity, we'll assume this is a single-player game. For multiplayer we'd usually store times individually for every player who joined.

os.time() actually gives the number of seconds since a particular chosen date called the unix epoch which is pretty standard among many languages. you can translate this into a date yourself, but that's a bit confusing. luckily, you can use the os.date() feature and pass in os.time() for the current time, a process which is also described in that article :)