如何获得一年中的12个月

时间:2014-05-07 08:00:27

标签: android

通过此声明,我将返回星期几

int dayOfWeak = mycal.get(Calendar.DAY_OF_WEEK);

        switch (dayOfWeak) {
            case Calendar.SUNDAY:
                break;
            case Calendar.MONDAY:
                break;
            case Calendar.TUESDAY:
                break;
            case Calendar.WEDNESDAY:
                break;
            case Calendar.THURSDAY:
                break;
            case Calendar.FRIDAY:
                break;
            case Calendar.SATURDAY:
                break;     

但是如何才能将12个月传递给显示适配器?

1 个答案:

答案 0 :(得分:0)

尝试使用SimpleDateFormat并使用模式MMMM

public String getMonth(){
  String format = "MMMM";
  SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
  return sdf.format(DATE_WITH_SPECIFIED_MONTH);
}

或想要获得整数值时的不同模式。

public int getMonth(){
  String format = "M";
  SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
  return sdf.format(DATE_WITH_SPECIFIED_MONTH);
}