Transforming Datetime into month, day and year?

后端 未结 7 1982
北恋
北恋 2020-12-13 04:36

I can\'t seem to find this and I feel like it should be easy. In Ruby on Rails, how do I take:

2010-06-14 19:01:00 UTC

and turn it into

7条回答
  •  我在风中等你
    2020-12-13 05:12

    Just the other day there was a similar question. In my answer how do I get name of the month in ruby on Rails? I showed how you can add a custom to_s definition in your config/environment.rb file.

    ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
     :my_own_long_date_format => "%B %d, %Y")
    

    Now you can call Time.now.to_s(:my_own_long_date_format) from any view to get:

    June 15, 2010
    

提交回复
热议问题