Monday, February 25, 2008

Rails Time and Database

Last few days I improved rails code related to time function in several places.


Rails extended basic Time class to give output in several format. So that you can output in database datetime format by passing :db symbol as argument to Time's to_s() method. Previously I produced database format manually"%Y-%m-%d %H:%M:%S").to_s
now, it simplifies to
Detail documentation can be found here

To parse database date to ruby Time, I used this.
where created_at is DateTime type field in Token model

To get back-and-forth between Unix Timestamp and ruby Time, you can simply use -
and to read -

No comments: