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:
<% @created = scenario.created_at %>
Then I will get:
2009-03-27 23:53:38 UTC
Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z"). Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of "+hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes ahead of UTC.
The T doesn't really stand for anything. It is just the separator that the ISO 8601 combined date-time format requires. You can read it as an abbreviation for Time. The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).
SQL Date Data Types TIMESTAMP - format: YYYY-MM-DD HH:MI:SS.
The strftime
(from Ruby's Time) and to_formatted_s
(from Rails' ActiveSupport) functions should be able to handle all of your time-formatting needs.
Take a look at the I18n functionality. It allows you to do the following in your views:
<%= localize(scenario.created_at, :format => :long) %>
where the formats are defined in your locales. More info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With