날짜에 특정 문자열을 구문 분석

Eltomon :

셀레늄을 통해 전체 테이블을 읽고 엑셀 파일에 결과를 작성하는 동안, 나는 현재 날짜 구문 분석 / 문제 형식에 직면하고 StringA의 Date객체를. 내가 아카이브에 원하는 것은 다음과 같은 형식입니다 :

dd-mm-yyyy

이 같은 테이블보기에서 검색되는 날짜 열

16 APR 2020

내가 사용하려고 SimpleDateFormat포맷을하지만 난을 얻고있다 ParseException.

java.text.ParseException: Unparseable date: "16 Apr 2020"
deHaar :

그냥 기록을 위해 :이 구문 분석하고 날짜를 포맷하는 방법이다 String와 현재 java.time(자바 8에서 사용할 수) :

public static void main(String[] args) {
    // the date String
    String d = "16 Apr 2020";
    // which is parsed to a LocalDate using a formatter with a suitable pattern
    LocalDate ld = LocalDate.parse(d, DateTimeFormatter.ofPattern("dd MMM yyyy"));
    // and which is then printed in a different format using a formatter with a differen pattern
    System.out.println(ld.format(DateTimeFormatter.ofPattern("dd-MM-yyyy")));
}

이것의 출력은

16-04-2020

추천

출처http://43.154.161.224:23101/article/api/json?id=338431&siteId=1