Formating date and time

I want to display date and time in view as “August 7, 2009 at 10:22:02
am”. Presently it is displaying in view as “2009-08-07 10:22:02 UTC”.
Can anyone tell to format date and time.

2009/8/8 Aashish K. [email protected]:

I want to display date and time in view as  “August 7, 2009 at 10:22:02
am”. Presently it is displaying in view as “2009-08-07 10:22:02 UTC”.
Can anyone tell to format date and time.

Have a look at strftime.
(Did you try googling for ruby format date time, Google is usually
quicker than posting here.).

Colin

THIS IS THE SOLUTION TRY THIS
<%=DateTime.now.strftime("%B %d %Y")%> <%= DateTime.now.strftime("%I:
%M%P " ) %>

If you want it formatted this way all the time, you might also want to
consider setting a format in Time::DATE_FORMATS via an initializer.

In your case, you’d drop this code into a file in config/initializers
(say, date_formats.rb):

Time::DATE_FORMATS[:default] = “%A %d %Y at %H:%M:%S”

That should be close to what you want - look at the docs for strftime
for more of the % symbols.

–Matt J.

On Aug 8, 5:45 am, Aashish K. [email protected]