ala*_*dey 20 formatting timestamp ruby-on-rails
如何以更易读的格式格式化Rails时间戳?如果我只是打印出来created_at或updated_at在我的视图中这样:
<% @created = scenario.created_at %>
Run Code Online (Sandbox Code Playgroud)
然后我会得到:
2009-03-27 23:53:38 UTC
Gre*_*ell 23
将strftime(从Ruby的时间)和to_formatted_s(从Rails的的ActiveSupport)函数应该能够处理所有的时间格式化的需求.
也
<%= l scenario.created_at, :format => :sample) %>
Run Code Online (Sandbox Code Playgroud)
在locales/en.yml(取决于语言)
en:
time:
formats:
sample: '%d.%m.%Y'
Run Code Online (Sandbox Code Playgroud)
要了解更多信息,请参阅 - http://guides.rubyonrails.org/i18n.html