Month name as a string

前端 未结 11 2162
悲哀的现实
悲哀的现实 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

    The only one way on Android to get properly formatted stanalone month name for such languages as ukrainian, russian, czech

    private String getMonthName(Calendar calendar, boolean short) {
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_MONTH_DAY | DateUtils.FORMAT_NO_YEAR;
        if (short) {
            flags |= DateUtils.FORMAT_ABBREV_MONTH;
        }
        return DateUtils.formatDateTime(getContext(), calendar.getTimeInMillis(), flags);
    }
    

    Tested on API 15-25

    Output for May is Май but not Мая

提交回复
热议问题