Rosh
Rosh

Reputation: 731

change default date format in ruby on rails?

I want to change default date format in Rails. Format should be y/m/d . I add following code into my environment.rb

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.
merge!(:default => '%Y/%m/%d')

But it didn't work. How can I change default format? I use rails 2.3.8 version

Upvotes: 11

Views: 7944

Answers (2)

dexter
dexter

Reputation: 13593

Add a file to config/initializers with the following code:

Date::DATE_FORMATS[:default]="%Y/%m/%d"
Time::DATE_FORMATS[:default]="%Y/%m/%d %H:%M"

Upvotes: 19

Rishav Rastogi
Rishav Rastogi

Reputation: 15492

Put that in a file in the config/initializers and that should work.

Upvotes: 0

Related Questions