Customizing datetime format in en.yml in Rails 3

后端 未结 4 1787
北海茫月
北海茫月 2021-02-01 18:15

According to documentation at http://guides.rubyonrails.org/i18n.html#adding-date-time-formats, the best way to ask for specific formats for a date is to define them in /config/

4条回答
  •  不知归路
    2021-02-01 19:08

    just want to clarify that if you use with active record, just simply convert the string datetime value to date object as example below.

    en:
      date:
        formats:
          default: "%Y-%m-%d"
          short: "%b %d"
          long: "%B %d, %Y"
    

    <%= l(post.the_created_at.to_date, format: :long) %>

提交回复
热议问题