In my view i want to diplay current date in mm/dd/yyyy format
+3
A:
You could simply do (substitute in Time
for DateTime
if using straight ruby -- i.e. no rails):
DateTime.now.strftime('%m/%d/%Y')
If you're using that format a lot, you might want to create a date_time_formats initializer in your RAILS_ROOT/config/initializers
folder (assuming Rails 2).
Something like this:
# File: date_time_formats.rb
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:human => "%m/%d/%Y"
)
Will then let you use the more friendly version of DateTime.now.to_s(:human)
in your code.
jerhinesmith
2010-09-09 14:57:56