What Is Os.Time And How Do I Use It?

I want to learn how to use os.time and what even is it. I tried to look everywhere but the explanation is too complicated. :wave:

print(os.time()) --> some big integer


print(os.time()) --> should be around the last printed integer +3

It’s just a thing that returns the LOCAL time, which is affected by the timezone of the running machine.


But why would I need the time from January 1970?

What do you mean, I don’t get it…

You don’t necessarily need January 1970, you just need the seconds from it. Why? If you want to make a timer or a temporary ban, you use the amount of seconds since the Unix Epoch to determine how much time has passed.

In @Feedekaiser’s example, they showed that 3 seconds had passed since the last time the function was called. It’s useful anything relating to time. Really any operating system or device you use, uses this.

1 Like

That is tick of what you are talking about, it doesn’t return the local time.

Thanks for the heads up.‌‌‌‌‌‌

os.time basically just returns how many seconds have passed since January, 1970.

Oh I see. So then how would I implement it or how would I use it. Like this?

local currentTime = os.time()


local time = os.time()

pritn("24 hours has passd by")

Yes, you can use it like that, but you can also do this:

local start = os.clock() -- you can also use os.time()
local connection

connection = game:GetService("RunService").Heartbeat:Connect(function()
    if os.clock() - start > 3 then
       print("more than 3 seconds have passed")

You can use wait as well.


Oh thanks a lot. Now I know. But one more question. Is os.time same thing as os.clock() ?

os.clock() just returns the amount of CPU being used by Lua in seconds (benchmarking), it’s used a lot but there’s alternatives like tick() and os.time(). Whichever one you want to use is up to you.

1 Like