Tuesday, June 27, 2006
Ruby convert Time to Date
On more than one occasion I've needed to convert a Time object to a Date. Generally, I use the following code:
Date.parse(Time.now.strftime('%Y/%m/%d'))I have two questions.
- Is there a better way?
- Why doesn't Time have a to_date method?
Comments:
<< Home
ActiveSupport implements Time#to_date. If you're not working on a Rails application, you could always borrow their implementation.
No kidding!
Date, Time, and File objects in ruby could learn something from the Java core API. Oh well.
Post a Comment
Date, Time, and File objects in ruby could learn something from the Java core API. Oh well.
<< Home



