Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        LocalDate[] a = getWeekday(LocalDate.now());

        System.out.println(Arrays.toString(a));
    }

    public static LocalDate[] getWeekday(LocalDate date) {
        int DAYS_OF_WEEK = 7;

        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;

    }
}