Returns LocalDate date of the Sunday of week to which provided date belongs to. - Java java.time

Java examples for java.time:Week

Description

Returns LocalDate date of the Sunday of week to which provided date belongs to.

Demo Code


//package com.java2s;
import java.time.DayOfWeek;
import java.time.LocalDate;

public class Main {
    /**/*ww  w . java 2  s  .  c o  m*/
     * Returns {@link LocalDate} date of the Sunday of week to which provided {@code date} belongs to.
     */
    public static LocalDate getWeekEnd(LocalDate date) {
        int daysToSunday = DayOfWeek.SUNDAY.getValue()
                - date.getDayOfWeek().getValue();
        return date.plusDays(daysToSunday);
    }
}

Related Tutorials