DateHelper { public static Date dateFromIsoString(final String dateText) { final DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME; final ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateText, dtf); return Date.from(zonedDateTime.toInstant()); } private  DateHelper(); static Date getGmtDate(); static Date dateFromIsoString(final String dateText);  }
@Test public void getDateFromStringEuropeParis() throws ParseException { final Date expected = this.getDate("2023-02-15 04:13:38.123+0100", "yyyy-MM-dd HH:mm:ss.SSSZ", TimeZone.getTimeZone("Europe/Paris")); final String dateText = "2023-02-15T04:13:38.123+01:00[Europe/Paris]"; final Date actual = DateHelper.dateFromIsoString(dateText); assertThat(actual).isEqualTo(expected); }
@Test public void getDateFromStringUTC() throws ParseException { final Date expected = this.getDate("2023-06-21 05:03:50.456Z", "yyyy-MM-dd HH:mm:ss.SSS", TimeZone.getTimeZone("UTC")); final String dateText = "2023-06-21T05:03:50.456Z"; final Date actual = DateHelper.dateFromIsoString(dateText); assertThat(actual).isEqualTo(expected); }