Gibraltar date formatting: expected GB-like format while got US-like one

Viewed 88

With Joda:

Locale locale = new Locale("en", "GI"); // Gibraltar
DateTimeFormatter formatter = DateTimeFormat.shortDate().withLocale(locale);
DateTime date = new DateTime(2019, 6, 20, 9, 30); // 20 June 2019
String formatted = date.toString(formatter);

With Java8:

Locale locale = new Locale("en", "GI"); // Gibraltar
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(locale);
LocalDateTime date = LocalDateTime.of(2019, 6, 20, 9, 30); // 20 June 2019
String formatted = formatter.format(date);

In both cases, formatted is equal to 6/20/19 while I was expecting 20/06/19, given that Wikipedia states that the Gibraltarian date format is dd/mm/yyyy.

Any idea of a fix (different from "if GI then GB")?

Note: when you use new Locale("en", "GB"), you do get the expected result.

0 Answers
Related