This program gets the current date using the LocalDate.now() method, and then uses the plusDays() method to calculate the date 10 days before and after the current date.
The LocalDate class is used to represent a date, and provides various methods for manipulating dates such as plusDays().
The plusDays() method takes an integer argument, which is the number of days to add (if positive) or subtract (if negative) from the current date. In this program, -10 is passed as the argument to plusDays() to get the date 10 days before the current date, and 10 is passed to get the date 10 days after the current date.
The output of the program includes the current date, as well as the dates 10 days before and after the current date. The output is displayed using the System.out.println() method.
import java.time.*; class GetDate_BeforeAfter { public static void main(String[] args) { LocalDate td = LocalDate.now(); System.out.println("Current Date: "+td); System.out.println("10 Days Before Today Date "+td.plusDays(-10)); System.out.println("10 Days After Today Date "+td.plusDays(10)); } }
Current Date: 2022-11-05 10 Days Before Today Date 2022-10-26 10 Days After Today Date 2022-11-1
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions