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

How to convert unix time to other units of time?

Asked by 4 years ago

The title pretty much explains itself. I need to convert time from the unix epoch into like the year month day or day of the week. LOL, thanks!

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

This is pretty simple to do actually, all yah have to do is use os.date to get a full table of year, month, weekday, day of the month, day of the year, current hour, current minute, second, ect.

local thing = os.date("*t",os.time())
local ap = ""

if thing.hour > 0 then
    ap = "PM"
else
    ap = "AM"
end

print(thing.day.."/"..thing.month.."/"..thing.year.."  "..math.abs(thing.hour-12)..":"..thing.min.." "..thing.sec.." seconds "..ap)

This will print out the exact time of the os.time() you input in the thing variable. Change os.time() to whatever just make sure it's a unix time. :D

0
lol thx DahWaffleGamer 37 — 4y
Ad

Answer this question