Transforming Datetime into month, day and year?

后端 未结 7 1968
北恋
北恋 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条回答
  •  萌比男神i
    2020-12-13 05:10

    I don't know for

    June 14th, 2010
    

    But if you want

    June 14, 2010
    

    Ref how do i get name of the month in ruby on Rails? or this

    Just do

    @date = Time.now
    @date.strftime("%B %d, %Y")
    

    And for suffix use following

    @date.strftime("%B #{@date.day.ordinalize}, %Y") # >>> Gives `June 18th, 2010`
    

提交回复
热议问题