Java date format real simple

后端 未结 4 2048
生来不讨喜
生来不讨喜 2021-01-24 17:09

how would you write te date if i have a date and all i want is the month and the day like this (mm/dd) and then turn the month like this July, 08

4条回答
  •  离开以前
    2021-01-24 17:50

    the month and the day like this (mm/dd) and then turn the month like this July, 08

    So you want to convert MM/dd to MMMM, dd? So you start with a String and you end up with a String? Then you need another SimpleDateFormat instance with the first pattern.

    String dateString1 = "07/08";
    Date date = new SimpleDateFormat("MM/dd").parse(dateString1);
    String dateString2 = new SimpleDateFormat("MMMM, dd").format(date);
    System.out.println(dateString2); // July, 08 (monthname depends on locale!).
    

提交回复
热议问题