0
單元的自定義功能,我已經轉換成時間單位時間如下自定義函數:轉換的時間
def time_expiry_text(time_expiry) # unit of time is hours
time_expiry_text = ''
if ((time_expiry/24) > 30) then # if more than 30 days use months as unit
months = ((time_expiry/24)/30)
time_expiry_text = months.to_s
time_expiry_text += months == 1 ? ' month' : ' months'
elsif time_expiry >= 24 then # if greater than or equal to 1 day or 24 hours use days as unit
days = time_expiry/24
time_expiry_text = days.to_s
time_expiry_text += days == 1 ? ' day' : ' days'
else
hours = time_expiry
time_expiry_text = hours.to_s
time_expiry_text += hours == 1 ? ' hour' : ' hours'
end
return time_expiry_text
end
我有兩個問題:
有時候我並不總是得到我想要的結果。例如,我得到了-2700小時的返回時間。
當時間的單位是幾個月,我也想要返回剩下的日子。例如,2個月和13天。
keruilin,邏輯是有點錯誤,因爲你認爲每個月是30天長。我會玩一些代碼併發佈一個答案 – Augusto 2011-03-18 11:02:51