How can I convert seconds to the format in subject.
Is there any function in Time or just need to program it?
How can I convert seconds to the format in subject.
Is there any function in Time or just need to program it?
On Wed, Oct 10, 2012 at 10:51 AM, ajay paswan [email protected]
wrote:
How can I convert seconds to the format in subject.
Is there any function in Time or just need to program it?
If there’s something built-in, I shouldn’t have bothered with
https://github.com/ymendel/one_inch_punch/blob/master/lib/punch/core_ext/fixnum.rb
years
ago.
def ptime sec
ground, sec = Time.new(2012, 1, 1, 0, 0), sec.abs
return sec.abs > 86400 ? nil : (ground + sec).strftime("%T")
end
On 10/10/2012 06:00 PM, Todd B. wrote:
def ptime sec
ground, sec = Time.new(2012, 1, 1, 0, 0), sec.abs
return sec.abs > 86400 ? nil : (ground + sec).strftime("%T")
end
Using modulo and default arguments, this can be simplified quite a bit:
def ptime sec
(Time.new(1) + sec % 86400).strftime “%T”
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs