Is there an easy way to format date/time strings with ruby? I know in .Net you can do something like this: datetime.tostring("MM/dd/yy hh:mm tt") => 09/12/05 09:12 AM Thanks, Matt _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
You have to start thinking in a more unixy way -- ruby has its roots in the unix / linux realm, so its methodologies will follow. There is an strftime() method on a Time object. See the help docs for formatting. Here''s how to output "On Jan 01, 2000 at 04:19 PM" (assuming variable t is a time object containing that value): <%= t.strftime("On %B %d, %Y at %I:%M %p") %> On 9/12/05, Matt Pantana <matt.pantana-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Is there an easy way to format date/time strings with ruby? I know in .Net > you can do something like this: > datetime.tostring("MM/dd/yy hh:mm tt") => 09/12/05 09:12 AM > Thanks, > Matt > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Brock Weaver brockweaver-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org /* you are not expected to understand this */ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Monday 12 September 2005 15:15, Matt Pantana wrote:> Is there an easy way to format date/time strings with ruby? I know in > .Net you can do something like this: > datetime.tostring("MM/dd/yy hh:mm tt") => 09/12/05 09:12 AMdatetime.strftime("%m/%d/%y %h:%M %p") $ ri strftime Michael -- Michael Schuerig Nothing is as brilliantly adaptive mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org as selective stupidity. http://www.schuerig.de/michael/ --A.O. Rorty, The Deceptive Self
Thanks, that''s perfect! On 9/12/05, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> > On Monday 12 September 2005 15:15, Matt Pantana wrote: > > Is there an easy way to format date/time strings with ruby? I know in > > .Net you can do something like this: > > datetime.tostring("MM/dd/yy hh:mm tt") => 09/12/05 09:12 AM > > datetime.strftime("%m/%d/%y %h:%M %p") > > $ ri strftime > > Michael > > -- > Michael Schuerig Nothing is as brilliantly adaptive > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org as selective stupidity. > http://www.schuerig.de/michael/ --A.O. Rorty, The Deceptive Self >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails