hi all,
in my rails application… i am displaying the dtae time… which is
coming from the database which property is timestamp… so in my view the
time is displaying as " Wed Apr 09 16:12:52 +0530 2008 "… but that in
not which i was actually… i need to display only themonth, date and
time… thats it… just like " Apr 09 16:12 " this… how to get the time
like this and display… can any one fine\d me a solution for this
aswell…
thankyou.
with regards,
barak
Use: to_formatted_s(format = :default)
for example commentDate.to_formatted_s(:db)
As per Rails docs:
to_formatted_s(format = :default)
Convert to a formatted string - see DATE_FORMATS for predefined
formats. You can also add your own formats to the DATE_FORMATS
constant and use them with this method.
This method is also aliased as to_s.
Examples:
date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
date.to_formatted_s(:db) # => “2007-11-10”
date.to_s(:db) # => “2007-11-10”
date.to_formatted_s(:short) # => “10 Nov”
date.to_formatted_s(:long) # => “November 10, 2007”
date.to_formatted_s(:long_ordinal) # => “November 10th, 2007”
date.to_formatted_s(:rfc822) # => “10 Nov 2007”
-Al
On Apr 9, 12:54 pm, Barak I. [email protected]