How do you format Rails timestamps in a more human-readable format? If I simply print out created_at
or updated_at
in my view like this:
you have to modify the timestamp file, in my case this file is located in /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.2.0/lib/active_record/timestamp.rb
. You must search for this line:
self.class.default_timezone == :utc ? Time.now.utc : Time.now
and change it to this:
self.class.default_timezone == :utc ? Time.now.utc : Time.now.strftime('%Y-%m-%d %H-%M-%S')
The trick is to modify the format with the strftime
method, you can change the format if you want.
Now rails will use your format to update the "updated_at" column.