Using LocalDate Class
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class StringToDate {
public static void main(String[] args) {
LocalDate localDate = LocalDate.now().plusDays(2);
System.out.println(localDate);//TodayDate +2 => 2022-01-28
String comparingDate = localDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));
System.out.println(comparingDate); //28-01-2022
}
}
Output :
2022-01-28
28-01-2022
Comments
Post a Comment