Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get all month names in the current locale in Rails

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.37k
    Comment on it


    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: