Access denied, Please sign in and make sure you have proper permission.
楼主没说转换的规则是什么。如果如楼上 @est 说的,那试试这样:
def float_to_time(v)
raise RangeError, ":(~~~" if v < 0 or v > 1
Time.at(v * 86400).utc.strftime("%H:%M:%S")
end
p float_to_time 0.5
Time.at(v * 86400).utc.strftime("%H:%M:%S"),这个不错
#4 楼 @bluexuemei 先求得秒,然后除以 86400 就可以了。
require 'time'
def time_to_float(s)
(Time.parse(s) - Time.parse("00:00:00")) / 86400
end