日付に特定の文字列を解析

Eltomon:

セレンを経由して、テーブル全体を読み取り、Excelファイルに結果を書き込むことを通して、私は現在の日付の解析/問題のフォーマットに直面していますStringDateオブジェクトを。私はアーカイブにしたいことは、次の形式であります:

dd-mm-yyyy

このようなテーブルルックから取得される日付ストリング

16 APR 2020

私が使用しようとしたSimpleDateFormatフォーマッタを私は取得していますParseException

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

念のために:これは、日付を解析してフォーマットする方法であるStringと、今日java.time(Javaの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=338433&siteId=1