Get Time (eg 16:45) | Scripting Help

So… I want to get the 24 hours time, like 16:45 or 08:13

In my script I can get the epox time with

local epox = os.time()

So I have the epox varible, but how do i get for examples 14:45

Maybe this can help:

You can use os.date() and os.time() together to have it in your desired format.

You can pretty easily do this like this, use os.date and pass your formatString and then the timestamp:

local ts = os.time();
print(os.date('%H:%M', ts)) --Prints 20:04, for me, as that is the time for me currently.
2 Likes

you can use os.date() for that, specifically:

os.date("*t")  -- to return local time
os.date("!*t") -- to return UTC time

I ended up using this script.

local stringToFormat = "%H:%M"

local timestamp = os.time()

local result = os.date(stringToFormat, timestamp)

print(result)

but @WaterJamesPlough script looks usable for me as well as it is split in half to my current one.

local ts = os.time();
print(os.date('%H:%M', ts))

Ok sure!
Mark it as the solution then.

Good luck on your projects, have a nice day!

I believe you understand that basically does the same thing, except you have differently formatted script with different variables.

Yeah, also, how would I make this an infinite loop which fires every minute?

while true do
    -- do something
    wait(60);
end;
1 Like

Thanks everryone.

I will soulotion this now.

you could do a while true do loop, that waits 60 Seconds after executing.

while true do
   --Bla Bla
   wait(60)
end
1 Like