next Week Day - Java java.time

Java examples for java.time:Week

Description

next 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[] nextWeekDay(LocalDate date) {

        if (date == null) {
            date = LocalDate.now();
        }//from  ww w .j  av  a 2s .c  om

        return getWeekday(date.plusWeeks(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