2010-07-13 13 views
0

날짜 형식 변환에 도움이 될 수 있습니까? 내 반환 날짜 개체가날짜 형식을 변환하는 방법

내가 "MM/dd/yyyy"이 날짜 형식을 변환하기 위해 노력하고있어하지만 난 구문 분석 예외를 받고 있어요 "Mon Jul 12 00:00:00 IST 2010"

이 포함되어 있습니다. 영업 이익의 코멘트에서


코드를 변환하는 방법을 제발 도와주세요 :

String mydatObj = myDate.toString(); 
Date formatedDate = getDateFormat(mydatObj); 
public static Date getDateFormat(String dateString) { 
    Date date = null; 
    SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); 
    try { 
     // set isLenient to false to adhere to the date format. 
     format.setLenient(false); 
     date = format.parse(dateString); 
    } catch (ParseException parseException) { 
     // ignore 
     LOG.error(parseException.getMessage(), parseException); 
    } 
    return date; 
} 
+1

뿐만 아니라 귀하의 질문에 –

답변

8

글쎄, 당신은 점점됩니다 ParseException 잘못된 형식의 날짜를 구문 분석하려고하기 때문이다. 여기

작은 코드 인 것이다 형식으로 일이 있습니다

// parse the date 
DateFormat f = new SimpleDateFormat("E MMM dd HH:mm:ss zzz yyyy"); 
Date d = f.parse("Mon Jul 12 00:00:00 IST 2010"); // works 

// now print the date 
DateFormat out = new SimpleDateFormat("MM/dd/yyyy"); 
System.out.println(out.format(d)); 
+0

일이 어쩌면 마지막 부분으로 그를 도와 올바른 형식의 코드를 추가하십시오) "MM/dd/yyyy"형식으로 날짜를 인쇄하십시오. – Cambium

+0

물론 ..... –

관련 문제