[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: how to get a time object from a date object ?

Devin Mullins

1/6/2007 6:42:00 PM

shawn bright wrote:
> lo there all, i have a date object, and i need to make a time object from
> it.
> i tried the to_i, ( what i really need are the seconds ) but it failed.
> I am
> sure that there is an easy way to do this, i just can't seem to find it.

Time.local(date.year, date.month, date.day)

(Courtesy of
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Conver...,
actually.)

2 Answers

William James

1/6/2007 7:33:00 PM

0


Devin Mullins wrote:
> shawn bright wrote:
> > lo there all, i have a date object, and i need to make a time object from
> > it.
> > i tried the to_i, ( what i really need are the seconds ) but it failed.
> > I am
> > sure that there is an easy way to do this, i just can't seem to find it.
>
> Time.local(date.year, date.month, date.day)
>
> (Courtesy of
> http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Conver...,
> actually.)

class DateTime
def to_time
Time.local( year, month, day, hour, min, sec )
end
end

puts (DateTime.now - 14).to_time

William James

1/6/2007 7:39:00 PM

0


Devin Mullins wrote:
> shawn bright wrote:
> > lo there all, i have a date object, and i need to make a time object from
> > it.
> > i tried the to_i, ( what i really need are the seconds ) but it failed.
> > I am
> > sure that there is an easy way to do this, i just can't seem to find it.
>
> Time.local(date.year, date.month, date.day)
>
> (Courtesy of
> http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Conver...,
> actually.)

class DateTime
def to_time
Time.local( year, month, day, hour, min, sec )
end
end

puts (DateTime.now - 14).to_time