Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function secondsToTime(seconds, places)
- local years = math.floor(seconds / (60 * 60 * 24 * 365))
- seconds = seconds % (60 * 60 * 24 * 365)
- local weeks = math.floor(seconds / (60 * 60 * 24 * 7))
- seconds = seconds % (60 * 60 * 24 * 7)
- local days = math.floor(seconds / (60 * 60 * 24))
- seconds = seconds % (60 * 60 * 24)
- local hours = math.floor(seconds / (60 * 60))
- seconds = seconds % (60 * 60)
- local minutes = math.floor(seconds / 60)
- seconds = seconds % 60
- if places == 6 then
- return string.format("%02d:%02d:%02d:%02d:%02d:%02d", years, weeks, days, hours, minutes, seconds)
- elseif places == 5 then
- return string.format("%02d:%02d:%02d:%02d:%02d", weeks, days, hours, minutes, seconds)
- elseif not places or places == 4 then
- return string.format("%02d:%02d:%02d:%02d", days, hours, minutes, seconds)
- elseif places == 3 then
- return string.format("%02d:%02d:%02d", hours, minutes, seconds)
- elseif places == 2 then
- return string.format("%02d:%02d", minutes, seconds)
- elseif places == 1 then
- return string.format("%02", seconds)
- end
- end
- function toSeconds(time)
- local seconds = 0
- local split = string.split(time, ":")
- if #split == 1 then
- seconds = tonumber(split[1])
- elseif #split == 2 then
- seconds = tonumber(split[1]) * 60
- seconds = seconds + tonumber(split[2])
- elseif #split == 3 then
- seconds = tonumber(split[1]) * 60 * 60
- seconds = seconds + tonumber(split[2]) * 60
- seconds = seconds + tonumber(split[3])
- elseif #split == 4 then
- seconds = tonumber(split[1]) * 60 * 60 * 24
- seconds = seconds + tonumber(split[2]) * 60 * 60
- seconds = seconds + tonumber(split[3]) * 60
- seconds = seconds + tonumber(split[4])
- elseif #split == 5 then
- seconds = tonumber(split[1]) * 60 * 60 * 24 * 7
- seconds = seconds + tonumber(split[2]) * 60 * 60 * 24
- seconds = seconds + tonumber(split[3]) * 60 * 60
- seconds = seconds + tonumber(split[4]) * 60
- seconds = seconds + tonumber(split[5])
- elseif #split == 6 then
- seconds = tonumber(split[1]) * 60 * 60 * 24 * 365
- seconds = seconds + tonumber(split[2]) * 60 * 60 * 24 * 7
- seconds = seconds + tonumber(split[3]) * 60 * 60 * 24
- seconds = seconds + tonumber(split[4]) * 60 * 60
- seconds = seconds + tonumber(split[5]) * 60
- seconds = seconds + tonumber(split[6])
- end
- return seconds
- end
Advertisement
Add Comment
Please, Sign In to add comment