Java Date Time Java Java API
java.time.MonthDay
public String format(DateTimeFormatter formatter)
Formats this month-day using the specified formatter.
package com.logicbig.example.monthday;import java.time.MonthDay;import java.time.format.DateTimeFormatter;public class FormatExample { public static void main(String... args) { MonthDay m = MonthDay.of(10, 3); System.out.println(m); format(m, "dd/MMM"); format(m, "dd-MMMM"); format(m, "d/M"); } private static void format(MonthDay m, String pattern) { DateTimeFormatter f = DateTimeFormatter.ofPattern(pattern); String s = m.format(f); System.out.printf("%s > %s%n", pattern, s); }}
--10-03dd/MMM > 03/Octdd-MMMM > 03-Octoberd/M > 3/10