Calculates which date the given weekday occurs next time. - Java java.time

Java examples for java.time:Week

Description

Calculates which date the given weekday occurs next time.

Demo Code


//package com.java2s;

import java.time.*;
import java.time.temporal.TemporalAdjusters;

public class Main {
    /**//  w  w  w  . jav a  2 s  . com
     * Calculates which date the given weekday occurs next time.
     *
     * @param day The weekday to find.
     * @return The next occurrence of the weekday.
     */
    public static LocalDate getNextDateOfDay(DayOfWeek day) {
        return LocalDate.now().with(TemporalAdjusters.next(day));
    }
}

Related Tutorials