How can I format day and month in the locale-correct order in Java?

后端 未结 2 1630
暖寄归人
暖寄归人 2021-01-19 18:35

Is there a way to format a day and month (in compact form), but not year, in the locale-correct order in Java/Kotlin? So for English it should be \"Sep 20\" but for Swedish

2条回答
  •  無奈伤痛
    2021-01-19 18:44

    You can do it in Java using LocalDate:

    LocalDate dt = LocalDate.parse("2019-09-20"); 
    System.out.println(dt);   
    DateTimeFormatter ft = DateTimeFormatter.ofPattern("dd MMM", new Locale("sv","SE")); 
    System.out.println(ft.format(dt));
    

提交回复
热议问题