how do I get name of the month in ruby on Rails?

后端 未结 6 948
眼角桃花
眼角桃花 2021-02-05 00:12

so i create in my view:

<%=date=Date.today%>

How do i get the name of the month out of the date? I was trying to do sth like



        
6条回答
  •  -上瘾入骨i
    2021-02-05 00:29

    If you have a particular custom date / time format which you need to use repeatedly then you can extend the ActiveSupport date / time helper.

    e.g. if you define the following in your config/environment.rb

    ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:full_english => "%A %B %d, %Y at %I:%M %p")
    

    then when you call Time.now.to_s(:full_english) in your views you will get something like:

    "Friday June 11, 2010 at 12:53 PM"
    

    Ruby's strftime method is well documented at http://apidock.com/ruby/Time/strftime

提交回复
热议问题