开发者

change default date format in ruby on rails?

开发者 https://www.devze.com 2023-03-29 23:22 出处:网络
I want to change default date format in Rails. Format should be y/m/d . I add following code into my environment.rb

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!开发者_如何学Go(:default => '%Y/%m/%d')

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


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"


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

0

精彩评论

暂无评论...
验证码 换一张
取 消