2013-03-29 3 views
0

긴 날짜 형식을 특정 간단한 날짜 형식으로 변환하십시오.긴 날짜를 특정 짧은 날짜 형식으로 변환

Datepicker (Jcalander)에서 날짜를 가져 오려면 dd-mm-yyyy 형식으로 형식을 지정하고 String 변수에 할당하고 싶습니다. 아래 코드를 사용해 보았습니다. 그러나 didnt는 나가 원하는 날짜 체재를 얻는다. 당신이 고정, 비 로케일에 의존하는 형식을 원하는 경우에

SimpleDateFormat simpleFormat = (SimpleDateFormat) jCalendarCombo1.getDateFormat(); 
Date date = jCalendarCombo1.getDate(); 
System.out.println(date); // Prints Thu Mar 28 00:00:00 IST 2013 


String s = simpleFormat.format(date); 
System.out.println(s); // prints Thursday, March 28, 2013 

System.out.println("Date SHORT format: " + DateFormat.getDateInstance(DateFormat.SHORT).format(date)); // prints 3/28/13 

답변

0

, 당신은 단지 그것을 자신을 만들 수 있습니다;

SimpleDateFormat shortformat = new SimpleDateFormat("dd-MM-yyyy"); 
String s = shortformat.format(date); 
System.out.println(s);      // Prints 29-03-2013 
+0

빠른 응답을 위해 Thnx. 이제 작동합니다. 29-03-2013 형식의 날짜가 있습니다. 다시 thnx. – amal