get Current Week Day - Java java.time

Java examples for java.time:Week

Description

get Current 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[] getCurrentWeekDay() {
        return getWeekday(null);
    }/*from  w w  w  .  java2  s . co m*/

    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