How do I get the last day of a month in Joda?
Category: org.joda.time, viewed: 824 time(s).
This example show you how to use Joda-Time's DateTime class to get the last day of the month. We use the dayOfMonth() property of this object an get the maximum value using the withMaximumValue() method which give us the last day of a month.
package org.kodejava.example.joda;
import org.joda.time.DateTime;
public class LastDayOfTheMonth {
public static void main(String[] args) {
//
// Creates an instance of DateTime.
//
DateTime dateTime = new DateTime();
//
// Get the last date of the month using the dayOfMonth property
// and get the maximum value from it.
//
DateTime lastDate = dateTime.dayOfMonth().withMaximumValue();
//
// Print the date and day name.
//
System.out.println("Date = " + lastDate.toString());
System.out.println("Day = " + lastDate.dayOfWeek().getAsText());
}
}
The example output is:
Date = 2012-02-29T23:41:12.231+08:00
Day = Wednesday
More examples on org.joda.time