Advertisement
BobMe

Military Clock Converter

Dec 3rd, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. --A script that will convert seconds, minutes, hours, or all 3 into a military time format.
  2. --I didn't actually know if there was a formula for this, so I just solved it using logic instead.
  3. --You can test it here: https://www.lua.org/cgi-bin/demo
  4.  
  5. seconds=0
  6. minutes=0
  7. hours=0
  8.  
  9. while seconds>60 do
  10. minutes=minutes+1
  11. seconds=seconds-60
  12. end
  13. while minutes>60 do
  14. hours=hours+1
  15. minutes=minutes-60
  16. end
  17.  
  18. if seconds==60 then seconds=seconds-60 minutes = minutes+1 end
  19. if minutes==60 then minutes=minutes-60 hours = hours+1 end
  20.  
  21. if seconds == 0 then
  22. seconds = "00"
  23. end
  24. if minutes == 0 then
  25. minutes = "00"
  26. end
  27. if hours == 0 then
  28. hours = "00"
  29. end
  30.  
  31. print("hh:mm:ss")
  32. print(hours..":"..minutes..":"..seconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement