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 can use strftime
to format the timestamp in many ways. I prefer some_data[:created_at].strftime('%F %T'). %F
shows "2017-02-08" (Calendar date extended), and %T
shows "08:37:48" (Local time extended).
For timezone issues, add this lines to your config/application.rb
file
config.time_zone = 'your_timezone_string'
config.active_record.default_timezone = :local