How to turn seconds (os.time) into a readable output?

Example:

(these are random numbers)

14444 -->> 00d 04h 10m 20s

1 Like

You can use os.date and you can convert it with one of the given formats. You can read more about it on the dev wiki page here

1 Like
local currTime = os.time()
local days = math.floor(currTime/86400)
local hours = math.floor((currTime % 86400)/3600)
local minutes = math.floor(((currTime % 86400) % 3600)/60)
local seconds = math.floor((((currTime % 86400) % 3600)%60)/1)
print(string.format("%id %ih %im %is", days, hours, minutes, seconds))

Output:
image

1 Like

Where it says “5h”, is it possibly able to make it “05h”?

(I don’t have much experience with os.time or strings in general.)

1 Like
local currTime = os.time()
local days = math.floor(currTime/86400)
local hours = math.floor((currTime % 86400)/3600)
local minutes = math.floor(((currTime % 86400) % 3600)/60)
local seconds = math.floor((((currTime % 86400) % 3600)%60)/1)
print(string.format("%id %02ih %02im %02is", days, hours, minutes, seconds))

New output with change:
image

3 Likes

Yes, changed in most recent reply. It’ll show 0x for hours, minutes and seconds.

It worked, thank you!

(characters)