DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendPattern("MM.yyyy")
.parseDefaulting(DAY_OF_MONTH, 31) // set 31
.toFormatter();
Просто установите DAY_OF_MONTH
с 31
, DAY_OF_MONTH
будет основываться на rangeUnit
, чтобы выбрать последний день из месяц анализа .
/**
* The day-of-month.
* <p>
* This represents the concept of the day within the month.
* In the default ISO calendar system, this has values from 1 to 31 in most months.
* April, June, September, November have days from 1 to 30, while February has days
* from 1 to 28, or 29 in a leap year.
* <p>
* Non-ISO calendar systems should implement this field using the most recognized
* day-of-month values for users of the calendar system.
* Normally, this is a count of days from 1 to the length of the month.
*/
DAY_OF_MONTH("DayOfMonth", DAYS, MONTHS, ValueRange.of(1, 28, 31), "day"),
Пример:
LocalDate parse = LocalDate.parse("02.2017", f);
System.out.println(parse.getDayOfMonth());
Вывод:
28