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