Transforming Datetime into month, day and year?

后端 未结 7 1991
北恋
北恋 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:16

    Needs the Time module for Time.parse and ActiveSupport for Integer#ordinalize:

    require 'time'
    require 'active_support'
    
    input = '2010-06-14 19:01:00 UTC'
    t = Time.parse(input)
    date = "%s %s, %d" % [t.strftime("%B"), t.day.ordinalize, t.year]
    # => "June 14th, 2010"
    

提交回复
热议问题