How to get the last date of a particular month with JodaTime?

How about:

LocalDate endOfMonth = date.dayOfMonth().withMaximumValue();

dayOfMonth() returns a LocalDate.Property which represents the “day of month” field in a way which knows the originating LocalDate.

As it happens, the withMaximumValue() method is even documented to recommend it for this particular task:

This operation is useful for obtaining a LocalDate on the last day of the month, as month lengths vary.

LocalDate lastDayOfMonth = dt.dayOfMonth().withMaximumValue();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)