This program demonstrates how to get the next and previous Friday dates from the current date using the java.time package. The java.time.LocalDate class is used to represent a date without time. The now() method is called on the LocalDate class to get the current date. TemporalAdjusters is a class that provides various methods to adjust dates. In this program, the next() and previous() methods are used with DayOfWeek.FRIDAY as the argument to get the next and previous Friday dates from the current date, respectively. The output of the program will be the next and previous Friday dates in the format of yyyy-mm-dd.
import java.time.*; import java.time.temporal.TemporalAdjusters; class Get_Friday { public static void main(String[] args) { LocalDate dt = LocalDate.now(); System.out.println("Next Friday: "+dt.with(TemporalAdjusters.next(DayOfWeek.FRIDAY))); System.out.println("Previous Friday: "+dt.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY))); } }
Next Friday: 2022-11-11 Previous Friday: 2022-11-04
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions