previous Week Day - Java java.time

Java examples for java.time:Week

Description

previous Week Day

Demo Code


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

import java.time.LocalDate;

public class Main {
    public static final int DAYS_OF_WEEK = 7;

    public static LocalDate[] previousWeekDay(LocalDate date) {

        if (date == null) {
            date = LocalDate.now();
        }//  ww  w.  j a va  2  s .  c o  m

        return getWeekday(date.minusWeeks(1));

    }

    public static LocalDate[] getWeekday(LocalDate date) {

        if (date == null) {
            date = LocalDate.now();
        }

        LocalDate begin = null;
        if (date.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
            begin = date;
        } else {
            begin = date.minusDays(date.getDayOfWeek().getValue());
        }
        LocalDate end = begin.plusDays(DAYS_OF_WEEK - 1);

        LocalDate localDate[] = { begin, end };

        return localDate;

    }
}

Related Tutorials