1. import java.time.LocalDate;
  2. import java.time.format.DateTimeFormatter;
  3. public class DateConfig {
  4. public static String getFormattedDate(LocalDate date, String format) {
  5. // Use a formatter to format the date according to the specified format.
  6. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
  7. return date.format(formatter);
  8. }
  9. public static LocalDate parseDate(String dateString, String format) {
  10. // Parse the date string using the specified format.
  11. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
  12. return LocalDate.parse(dateString, formatter);
  13. }
  14. public static void main(String[] args) {
  15. // Example usage:
  16. LocalDate today = LocalDate.now();
  17. // Format the date as "yyyy-MM-dd"
  18. String formattedDate = getFormattedDate(today, "yyyy-MM-dd");
  19. System.out.println("Formatted Date: " + formattedDate);
  20. //Parse a date string from "MM/dd/yyyy"
  21. String dateString = "12/25/2023";
  22. LocalDate parsedDate = parseDate(dateString, "MM/dd/yyyy");
  23. System.out.println("Parsed Date: " + parsedDate);
  24. }
  25. }

Add your comment