Advertisement
Arc13

FormatSeconds API

Oct 24th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | None | 0 0
  1. function formatSeconds(nSeconds)
  2.   local nSec = nSeconds % 60
  3.   local nMin = math.floor((nSeconds /  60) % 60)
  4.   local nHour = math.floor((nSeconds / 3600) % 24)
  5.   local nDay = math.floor(nSeconds / 86400)
  6.  
  7.   local sReturnString = string.format("%02d:%02d:%02d:%02d", nDay, nHour, nMin, nSec)
  8.  
  9.   if nMin == 0 and nHour == 0 and nDay == 0 then
  10.     sReturnString = string.format("%02d:%02d", nMin, nSec)
  11.   elseif nHour == 0 and nDay == 0 then
  12.     sReturnString = string.format("%02d:%02d", nMin, nSec)
  13.   elseif nDay == 0 then
  14.     sReturnString = string.format("%02d:%02d:%02d", nHour, nMin, nSec)
  15.   end
  16.  
  17.   return sReturnString
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement