Skip to content

Instantly share code, notes, and snippets.

@hadrienblanc
Created July 28, 2020 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadrienblanc/57bdfe2be380ce2e750bc5604edf47f5 to your computer and use it in GitHub Desktop.
Save hadrienblanc/57bdfe2be380ce2e750bc5604edf47f5 to your computer and use it in GitHub Desktop.

Assuming that total_seconds = 3600

Option 1:

distance_of_time_in_words(total_seconds) #=> "about 1 hour"

Option 2:

Time.at(total_seconds).utc.strftime("%H:%M:%S") #=> "01:00:00"

Option 3:

seconds = total_seconds % 60
minutes = (total_seconds / 60) % 60
hours = total_seconds / (60 * 60)

format("%02d:%02d:%02d", hours, minutes, seconds) #=> "01:00:00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment