Advertisement
skypop

timeStr

Jun 15th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.52 KB | None | 0 0
  1. -- Formate un nombre de secondes en dur?e lisible
  2. function timeStr(sec)
  3.     local d = math.floor(sec/86400) --24*60*60 sec
  4.     local h = math.floor(sec/3600)%24 -- 60x60 sec
  5.     local m = math.floor(sec/60)%60 -- 60sec
  6.     local s = math.floor(sec%60) --Reste
  7.     local str = ""
  8.     if d>0 then str = d>1 and d.." days " or "1 day " end
  9.     if h>0 then str = str..h.."h" end
  10.     if m>0 then str = str..(m>9 and m or "0"..m) end
  11.     if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
  12.     return str
  13. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement