Name of this month (Date.today.month as name)

前端 未结 6 941
南笙
南笙 2020-12-12 16:46

I\'m using Date.today.month to display the month number. Is there a command to get the month name, or do I need to make a case to get it?

6条回答
  •  不思量自难忘°
    2020-12-12 17:26

    You can also use I18n:

    I18n.t("date.month_names") # [nil, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
    I18n.t("date.abbr_month_names") # [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    I18n.t("date.month_names")[Date.today.month] # "December"
    I18n.t("date.abbr_month_names")[Date.today.month] # "Dec"
    

提交回复
热议问题