There are number of ways to get the names of the all the months in the current locale. I am using the Ruby I18n gem which comes along with Rails.
This gem provides number of methods to perform these localisation tasks.
To get the month names you can use :
2.1.5 :001 > I18n.t("date.month_names")
=> [nil, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
This gives us all the month names in the form of an Array, and we can use it as per our need.
If we want the name of the months in abbreviated form we can write :
2.1.5 :009 > I18n.t("date.abbr_month_names")
=> [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
0 Comment(s)