Month name as a string

前端 未结 11 2138
悲哀的现实
悲哀的现实 2020-11-27 02:49

I\'m trying to return the name of the month as a String, for instance \"May\", \"September\", \"November\".

I tried:

int month = c.get(Calendar.MONTH         


        
11条回答
  •  [愿得一人]
    2020-11-27 03:40

    Use this :

    Calendar cal=Calendar.getInstance();
    SimpleDateFormat month_date = new SimpleDateFormat("MMMM");
    String month_name = month_date.format(cal.getTime());
    

    Month name will contain the full month name,,if you want short month name use this

     SimpleDateFormat month_date = new SimpleDateFormat("MMM");
     String month_name = month_date.format(cal.getTime());
    

提交回复
热议问题