2012-07-28 3 views
2

내 달을 SimpleDateFormat을 사용하여 MMM 형식으로 변환하려하지만 변환 할 수 없습니다.월을 MMM 형식으로 변환

tvDisplayDate = (TextView) findViewById(R.id.dateDisplay); 

    Calendar cal=Calendar.getInstance(); 

    SimpleDateFormat format = new SimpleDateFormat("MMM"); 

    int tempyear = cal.get(Calendar.YEAR); 
    int tempmonth = cal.get(Calendar.MONTH); 
    int tempday = cal.get(Calendar.DAY_OF_MONTH); 

    String month = new Integer(tempmonth).toString(); 

답변

4

다음 작품을 (난 그냥 그것을 테스트) 내가 사용 Joda Time

Calendar cal=Calendar.getInstance(); 
int tempmonth = cal.get(Calendar.MONTH); 

SimpleDateFormat newformat = new SimpleDateFormat("MMM"); 
SimpleDateFormat oldformat = new SimpleDateFormat("MM"); 

     String monthName = null; 
     Date myDate; 
     try { 
      myDate = oldformat.parse(String.valueOf(tempmonth)); 
      monthName = newformat.format(myDate); 
     } catch (ParseException e) { 
      e.printStackTrace(); 
     } 

     Log.d("MMM", monthName); 
0

실제로 만든 형식을 사용하고 있지 않습니다. 시도 :

String month = format.format(tempmonth); 

은 당신이 한 번에 모든 날짜를 포맷 할 수 있습니다 :

String dateString = sdf.format(cal.getTime()); 
0

을 것이라고 말하고 싶지만 그런 일을 더 쉽게 만들어라.

어쨌든 this 여기에 몇 가지 답변이 있습니다.