Advertisement
EconomicSerg

Seconds To Timestamp

Dec 18th, 2022
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. -- Credit to AlvinBlox
  2. function SecondsToTimestamp(seconds)
  3.     seconds = math.max(seconds, 0) -- Get the highest value between seconds and 0
  4.    
  5.     local minutes = tostring(math.floor(seconds / 60)) -- Minutes
  6.     local leftoverSeconds = tostring(seconds % 60) -- Seconds leftover from the minutes
  7.    
  8.     if #leftoverSeconds == 1 then
  9.         -- Add an extra '0' because this is a single digit number (9, 8, 7, 6, etc.)
  10.         leftoverSeconds = "0"..leftoverSeconds
  11.     end
  12.    
  13.     return minutes..":"..leftoverSeconds
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement