Alex Rivera | Logout

First day of next month with java Joda-Time

Asked 2011-01-24T19:25:20.870
44

How would you rewrite the method below, which returns the first day of next month, with the org.joda.time package in Joda-Time?

public static Date firstDayOfNextMonth() {
    Calendar nowCal = Calendar.getInstance();
    int month = nowCal.get(Calendar.MONTH) + 1;
    int year = nowCal.get(Calendar.YEAR);

    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    Date dueDate = new Date(cal.getTimeInMillis());

    return dueDate;
}
Edit
Report

1 Answer

1

localDate = new LocalDate().plusMonths(1).withDayOfMonth(1);

answered 2011-01-24T19:36:19.513

Your Answer