ruby on rails - Change default date format to %Y%m%d%H%M%S -
i'm using rails 3 , want change default date format of created_at , updated_at date when save them db.
default date format %y-%m-%d %h:%m:%s
, %y%m%d%h%m%s
where should change format? i'm trying create time_formats.rb in initializer folder.
here content:
class timeformats time::date_formats[:db] = "%y%m%d%h%m%s" time::date_formats[:default] = "%y%m%d%h%m%s" end
this not work. there can me? thank you.
the time , date formats define in initializers apply when converting them strings in ruby. formats you've defined used time.now.to_s(:default)
.
i don't recommend (nor aware of way how) change how dates stored in database. should let database store them default, change how formatted in views using .to_s(:format)
defined in initializers.
Comments
Post a Comment