2013-04-28 4 views
-2

나는 다음과 같은 경우 :시간을 초 단위로 포맷하는 방법은 무엇입니까?

LogEntry.format_time(3600).should eql("01:00:00") 

어떻게이 일을?

+0

자세한 정보, 배경 정보를 제공해주십시오. –

+0

방금 ​​비슷한 질문을 던졌습니다 : http://stackoverflow.com/questions/16268372/how-to-extract-logic-out-of-a-model-into-a-more-generic-way-for-rails, 둘 다 모호한 정보를 가지고있다. – kiddorails

답변

2

LogEntry 모델에 다음을 추가하십시오.

class LogEntry < ActiveRecord::Base 
    #your properties and attributes 
    def self.format_time(seconds) 
    Time.at(seconds).utc.strftime("%H:%M:%S") 
    end 
end 
+0

정말 고마워요. 나는 이것이 존재한다는 것을 전혀 몰랐다. –

관련 문제