2016-08-23 2 views
-1

에 내 JDBC에 실습을위한 날짜 문자열을 변환하려고하면 다음과 같은 방법변환 문자열 날짜-JAVA

 DateFormat Formatter=null; 
     Date convertedDate=null; 
     Formatter=new SimpleDateFormat("DD-MMM-YYYY",Locale.ENGLISH); 
     try { 
      convertedDate=(Date)Formatter.parse(date); 
     } catch (ParseException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
     java.sql.Date sqlDate=new java.sql.Date(convertedDate.getTime()); 
     System.out.println(date); 
     System.out.println(convertedDate); 
내가 '30 전달하고 만약 내가 직면하고 문제는, 예를 들면

을 시도 - NOV-2001 '을 매개 변수로 사용하여 DateFormat을 사용하여 Date로 변환하고 convertedDate에 저장하면 "Sun Dec 31 00:00:00 IST 2000"이 출력으로 잘못 처리됩니다. 제발 도와주세요. 이에.

+3

에 달

Oracle docs의 날 "(= 새 SimpleDateFormat의 포맷터와 노력을 의미 dd-MMM-yyyy ", Locale.ENGLISH); – SpringLearner

+2

[서식을 지정할 때 항상 사용하는 형식의 의미를 확인하십시오.] (http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html) – SomeJavaGuy

답변

2

하면, "dd-MMM-yyyy"를 사용할 필요가

DateFormat Formatter=null; 
     Date convertedDate=null; 
     Formatter=new SimpleDateFormat("DD-MMM-YYYY",Locale.ENGLISH); 
     try { 
      convertedDate=(Date)Formatter.parse(date); 
     } catch (ParseException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
     java.sql.Date sqlDate=new java.sql.Date(convertedDate.getTime()); 
     System.out.println(date); 
     System.out.println(convertedDate); 

D가 의미 해 일 d를 추가 정보를

+0

감사합니다. 그것은 작동합니다 :) –

+0

@SaiSankalp 기쁘다 – SpringLearner

+0

그래, 내가 대답을 수락했습니다. 당신의 도움에 감사드립니다. –