Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #Time of your with two digit in minutes like 5 to 50
  2. time_val="13.50"
  3. #split by "."
  4. split_val=time_val.split('.')
  5. #get a hours
  6. hour_val=split_val[0]
  7. #get a minutes
  8. min_val= (100*60)/split_val[1].to_i
  9. if(min_val == 60)
  10. hour_val +=1
  11. min_val=0
  12. end
  13. #it's concat a hours and minutes then it's final result
  14. final_time= hour_val.to_s + ":" + min_val + ":00"
  15.  
  16. sec = (13.5 * 3600).to_i
  17. min, sec = sec.divmod(60)
  18. hour, min = min.divmod(60)
  19. "%02d:%02d:%02d" % [hour, min, sec] # => "13:30:00"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement