I can''t find how to format dates in Rails. For example I want to display a datetime as: "Tuesday, April 10th, 2007" The closest I''ve been able to get is something like: foo.created_at.to_s(:short) Is there a way to pass options into the to_s method? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The "Time" class supports the POSIX standard "strftime()"
function... This
should get you everything except the "th" part:
foo.created_at.strftime("%A, %B %-e, %Y");
Cheers,
Tyler
Arch Stanton <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> I can''t find how to format dates in Rails.
>
> For example I want to display a datetime as:
>
> "Tuesday, April 10th, 2007"
>
> The closest I''ve been able to get is something like:
>
> foo.created_at.to_s(:short)
>
> Is there a way to pass options into the to_s method?
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
--
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> I can''t find how to format dates in Rails.> For example I want to display a datetime as: > "Tuesday, April 10th, 2007" see: http://whytheluckystiff.net/ruby/pickaxe/html/ref_c_time.html#Time.strftime --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---