Java로이 변환을 수행하려면 어떻게해야합니까?"2013 년 2 월 1 일 금요일"에서 "2013-02-01"로 변환
현재 내가하고 있어요 :
public static String formatDate(String strDateToFormat) {
try {
SimpleDateFormat sdfSource = new SimpleDateFormat("EEEE, MMMM DD, YYYY");
Date date = sdfSource.parse(strDateToFormat);
SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd");
return sdfDestination.format(date);
} catch (ParseException pe) {
System.err.println("Parse Exception : " + pe);
}
return null;
}
그러나 이것은 잘못된 형식을 초래한다.
Friday, February 1, 2013 > 2013-01-04
Thursday, January 31, 2013 > 2013-01-03
출력을 여러 번 반복 한 이유는 무엇입니까? –
"yyyy"로 "DD"를 "yyyy"로 변경하십시오. –
System.err.println ("Parse Exception :"+ pe);를'pe.printStackTrace(); '로 바꿉니다. 또는, 더 나은 방법은 해당 예외를 던지십시오. –