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

后端 未结 6 954
眼角桃花
眼角桃花 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条回答
  •  旧巷少年郎
    2021-02-05 00:23

    If you are looking solely to the month name, the Date::MONTHNAMES constant provided by rails is the easiest solution for you:

       Date::MONTHNAMES = 
       [
        [ 0] nil,
        [ 1] "January",
        [ 2] "February",
        [ 3] "March",
        [ 4] "April",
        [ 5] "May",
        [ 6] "June",
        [ 7] "July",
        [ 8] "August",
        [ 9] "September",
        [10] "October",
        [11] "November",
        [12] "December"
       ]
    

提交回复
热议问题