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 -- Posted via http://www.ruby-forum.com/.
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 -- Posted via http://www.ruby-forum.com/.
Aldric Giacomoni wrote:> 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_sThanks for the quick response. This is exactly what I was looking for! -- Posted via http://www.ruby-forum.com/.
2009/10/12 David Smit <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Aldric Giacomoni wrote: >> 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 > > Thanks for the quick response. This is exactly what I was looking for! >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. http://www.ruby-doc.org/core/classes/Time.html#M000298 Cheers. -- Posted via http://www.ruby-forum.com/.
Time.now.strftime("%d %b %Y %H:%M") => "12 Oct 2009 18:50" On Oct 12, 2:29 pm, David Smit <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > -- > Posted viahttp://www.ruby-forum.com/.
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. On Oct 12, 6:51 pm, Rick <richard.t.ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Time.now.strftime("%d %b %Y %H:%M") => "12 Oct 2009 18:50" > > On Oct 12, 2:29 pm, David Smit <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > 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 > > -- > > Posted viahttp://www.ruby-forum.com/.