Formatting Dates in my view

Hi,

Currently my dates look like this: 2009-10-10 00:55:37 UTC

I want to format them in my view to look like this: 10 Oct 2009 00:55

Is it possible to do the formatting in the view using the to_s method?

Thanks,

David

David Smit wrote:

Currently my dates look like this: 2009-10-10 00:55:37 UTC I want to format them in my view to look like this: 10 Oct 2009 00:55 Is it possible to do the formatting in the view using the to_s method?

How about: http://apidock.com/rails/ActiveSupport/TimeWithZone/to_s

You can use strftime if you need more control.

Colin

This is how I format dates in one of my projects:

message.created_at.strftime("%b %d %Y at %H:%M")

That gives "Jun 12 2009 at 11:34" if I remember correctly. Just play with it, very simple.

Cheers.

Time.now.strftime("%d %b %Y %H:%M") => "12 Oct 2009 18:50"

You can put something like this in your environment.rb if you will be using that format often:

ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(   :show_time => "%l:%M%p",   :reminder_time => "%B %d, %Y",   :simple_time => "%H:%M:%S" )

Then just to something like Time.now.to_s(:simple_time)

Don't forget to restart your server.