in Ruby, conversion of float integer into %H %M %S time

来源:互联网 发布:linux 安装python 编辑:程序博客网 时间:2024/06/15 21:40

How do you convert a float, say 13.5, to the corresponding 24-hour time %H:%M:%S? (13.5 would be 13:30:00, 8.25 would be 8:15:00) I'm still figuring the Time class...it confuses me

sec = (13.5 * 3600).to_imin, sec = sec.divmod(60)hour, min = min.divmod(60)"%02d:%02d:%02d" % [hour, min, sec] # => "13:30:00"

0 0
原创粉丝点击