fork download
  1. import java.time.LocalDate;
  2. import java.time.format.DateTimeFormatter;
  3. import java.time.format.FormatStyle;
  4. import java.util.Locale;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("uuuuMMdd", Locale.ENGLISH);
  9.  
  10. // A sample date string
  11. String strDate = "20210630";
  12. LocalDate date = LocalDate.parse(strDate, dtfInput);
  13.  
  14. System.out.println(date.format(getShortDateFormatterForLocale(Locale.getDefault())));
  15. System.out.println(date.format(getShortDateFormatterForLocale(Locale.GERMANY)));
  16. System.out.println(date.format(getShortDateFormatterForLocale(Locale.US)));
  17. }
  18.  
  19. static DateTimeFormatter getShortDateFormatterForLocale(Locale locale) {
  20. return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).localizedBy(locale);
  21. }
  22. }
Success #stdin #stdout 0.1s 52340KB
stdin
Standard input is empty
stdout
6/30/21
30.06.21
6/30/21