tags:

views:

417

answers:

2

In Perl you can do:

my $current_time = DateTime->now();
my $mdy = $current_time->mdy("/");

What's the easiest way to do this in Ruby?

+13  A: 
Time.now.strftime("%m/%d/%y")
sepp2k
+1 However, note that `strftime` is available in Perl as well and http://search.cpan.org/perldoc/DateTime has a lot of functionality beyond the simple example here.
Sinan Ünür
+1, though it sucks that "strftime" is such a terrible name.
Horace Loeb
strftime is the name of the underlying C library that implements these format strings. It's the standard name across all languages for this particular date format.
mpeters
@mpeters - Just because it's standard doesn't mean it's good. Naming `creat()` without the e at the end was just a terrible design mistake, and naming functions with names like `strftime()` is equally bad. We can see why it was done in the past, but here in the present it's horrible.
Chris Lutz
+2  A: 

I wrote a gem to help with formatting dates, and keeping your views DRY (not having to strftime every time you want to format dates).

Check it out at: http://github.com/platform45/easy_dates

Ryan
Very useful, thanks
Horace Loeb