Return the next date using java LocalDate library
In this article, we will give a date and after a given day our program return the next date. Using The plusDays() method of a LocalDate class in Java.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import java.time.LocalDate; import java.util.Scanner; public class FindNextDate { public String getNextDate(int year, int month, int day) { LocalDate date = LocalDate.of(year, month, day); String nextDay = date.plusDays(1).toString(); return nextDay; } public static void main(String[] args) { int year, month, day; Scanner input = new Scanner(System.in); System.out.println("Enter the date (yyyy-mm-dd):"); String x = input.nextLine(); String[] s = x.split("-"); year = Integer.parseInt(s[0]); month = Integer.parseInt(s[1]); day = Integer.parseInt(s[2]); FindNextDate next = new FindNextDate(); System.out.println(next.getNextDate(year, month, day)); } } |
Output
Enter the date (yyyy-mm-dd): 2020-2-29 2020-03-01