如何在 Ruby 中将日期格式化为 mm/dd/yyyy?
问题描述:
在 Perl 中,您可以:
In Perl you can do:
my $current_time = DateTime->now();
my $mdy = $current_time->mdy("/");
在 Ruby 中最简单的方法是什么?
What's the easiest way to do this in Ruby?
答
strftime
方法可用于格式化时间:
The strftime
method can be used to format times:
Time.now.strftime("%m/%d/%Y")