function module:get(timeInSeconds)
local result=nil
local years,months,day,hour,minute
years=math.round(timeInSeconds/31556926)
months=math.round((timeInSeconds%31556926)/2629744)
day=math.round((timeInSeconds%2629744)/86400)
hour=math.round((timeInSeconds%86400)/3600)
minute=math.round((timeInSeconds%3600)/60)
if years>0 then
result=years.."y "..months.."m "..day.."d "..hour.."h "..minute.."m"
elseif months>0 then
result=months.."m "..day.."d "..hour.."h "..minute.."m"
elseif day>0 then
result=day.."d "..hour.."h "..minute.."m"
elseif hour>0 then
result=hour.."h "..minute.."m"
elseif minute>0 then
result=minute.."m"
else
result=timeInSeconds.."s"
end
return result
end
3 Likes
Wouldn’t this be more efficient?
local function timestamp(s:number?):string
return os.date("%Yy %mm %dd %Hh %Mm %Ss",s)
end
1 Like
i tested this code but it wasn’t perfectly displaying the date
heres the output
2y 12m 20d 0h 0m --my code output
1971y 12m 22d 00h 00m 00s