t = 236.123 # 已播放(毫)秒数
s = Time.at(t).utc.strftime("%H:%M:%S.%L") # 转换成时间轴
=> "00:03:56.122"
(Time.parse(s).to_f - Time.now.beginning_of_day.to_f).round(3) # 还原
=> 236.122
def sec_to_time(duration)
Time.at(duration.to_d).utc.strftime("%H:%M:%S.%L")
end
def time_to_sec(time)
(Time.parse(time) - Time.now.beginning_of_day).round(3)
end
d = 236.123
puts t = sec_to_time(d)
# => 00:03:56.123
puts time_to_sec(t)
# => 236.123