Get next day in Java

In this source code example, we show you how to get the next day using Java 8 LocalDate class.

Get next day in Java Example

package com.ramesh.java8.datetime;

import java.time.LocalDate;

/**
 * Useful Java8DateUtiliy Methods
 * @author javaguides.net
 *
 */

public final class Java8DateUtility {

    /**
     * Get next day.
     * @param localDate
     * @return
    */
    public static LocalDate getNextDay(LocalDate localDate) {
         return localDate.plusDays(1);
    }
}

JUnit test case

package com.ramesh.java8.datetime;

import static org.junit.Assert.assertNotNull;

import java.time.LocalDate;
import org.junit.Test;

/**
 * JUnit test cases for Java8DateUtiliy Methods
 * @author javaguides.net
 *
 */
public class Java8DateUtilityTest {

    @Test
    public void getNextDayTest() {
        LocalDate date = Java8DateUtility.getNextDay(LocalDate.now());
        System.out.println("Next Day ::" + date);
        assertNotNull(date);
    }
}
Run the JUnit test cases will print the output:
Next Day ::2018-07-22

Comments