我想将LocalDate
显示为:
first day: 1st;
second day: 2nd;
third day: 3rd;
all rest days: Nth.
例如1980-10-1
为1st Oct 1980
我可以使用DateTimeFormatter.ofPattern("dth MMM yyyy")
进行序列化(不包括前三天)。
由于前三天的模式与休息日不同,因此如何构造格式化程序以使前三天也序列化?
答案 0 :(得分:2)
这是一个例子:
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
Map<Long, String> mapToRoman = new HashMap<>();
mapToRoman.put(1L, "1st");
mapToRoman.put(2L, "2nd");
mapToRoman.put(3L, "3rd");
mapToRoman.put(4L, "4th");
// continue to map all available days in a month
builder.appendText(ChronoField.DAY_OF_MONTH, mapToRoman );
builder.append(DateTimeFormatter.ofPattern(" MM yyyy", Locale.US));
DateTimeFormatter formatter = builder.toFormatter();