Skip to content

Instantly share code, notes, and snippets.

@lalitlogical
Created February 6, 2019 10:49
Show Gist options
  • Save lalitlogical/e7ba633f4b1dd377063e5ce60f0471e1 to your computer and use it in GitHub Desktop.
Save lalitlogical/e7ba633f4b1dd377063e5ce60f0471e1 to your computer and use it in GitHub Desktop.
how to convert 270921sec into days + hours + minutes + sec ? (ruby)
t = 270921
mm, ss = t.divmod(60) #=> [4515, 21]
hh, mm = mm.divmod(60) #=> [75, 15]
dd, hh = hh.divmod(24) #=> [3, 3]
puts "%d days, %d hours, %d minutes and %d seconds" % [dd, hh, mm, ss]
#=> 3 days, 3 hours, 15 minutes and 21 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment