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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: how to get a time object from a date object ?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password