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

Java examples for java.time:Week

Description

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

Demo Code


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

public class Main {
    /**/* w w  w  . j a v a2s. com*/
     * Returns {@link LocalDate} date of the Monday of week to which provided {@code date} belongs to.
     */
    public static LocalDate getWeekStart(LocalDate date) {
        int daysToMonday = date.getDayOfWeek().getValue()
                - DayOfWeek.MONDAY.getValue();
        return date.minusDays(daysToMonday);
    }
}

Related Tutorials