Skip to content

Instantly share code, notes, and snippets.

@pramoth
Created October 3, 2018 17:36
Show Gist options
  • Select an option

  • Save pramoth/a92213acd7f10a9a56304c5f60aa4cb2 to your computer and use it in GitHub Desktop.

Select an option

Save pramoth/a92213acd7f10a9a56304c5f60aa4cb2 to your computer and use it in GitHub Desktop.
LocalDate expectDate = LocalDate.of(2018,9,10);
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
.appendOptional(DateTimeFormatter.ofPattern("yyyy M d"))
.appendOptional(DateTimeFormatter.ofPattern("d M yyyy"))
.appendOptional(DateTimeFormatter.ofPattern("d.M.yyyy"))
.appendOptional(DateTimeFormatter.ofPattern("d/M/yyyy"))
.toFormatter();
assertThat(LocalDate.parse("2018 09 10",dateTimeFormatter)).isEqualTo(expectDate);
assertThat(LocalDate.parse("10 9 2018",dateTimeFormatter)).isEqualTo(expectDate);
assertThat(LocalDate.parse("10.09.2018",dateTimeFormatter)).isEqualTo(expectDate);
assertThat(LocalDate.parse("10/9/2018",dateTimeFormatter)).isEqualTo(expectDate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment