Search code examples
javadatejodatimedayofweek

Get first day of a particular week


In Joda-Time, is there a way to get the date of the first day of the week(Monday)?

For instance, I want to find out what date this week's Monday was based on today's current date 21/01/11.

Cheers in advance.

Edit: I also wish to find the date for the end of the week i.e. Sunday's date. cheers


Solution

  • Try LocalDate.withDayOfWeek:

    LocalDate now = new LocalDate();
    System.out.println(now.withDayOfWeek(DateTimeConstants.MONDAY)); //prints 2011-01-17
    System.out.println(now.withDayOfWeek(DateTimeConstants.SUNDAY)); //prints 2011-01-23