Write a Java program to demonstrate the use of an interface for custom date and time manipulation
import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; interface DateTimeManipulator { String formatDateTime(LocalDateTime dateTime, String pattern); } public class Main { public static void main(String[] args) { DateTimeManipulator dateTimeManipulator = (dateTime, pattern) -> { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); return dateTime.format(formatter); }; LocalDateTime now = LocalDateTime.now(); String formattedDateTime = dateTimeManipulator.formatDateTime(now, "dd-MM-yyyy HH:mm:ss"); System.out.println("Formatted Date and Time : " + formattedDateTime); } }
Formatted Date and Time : 29-11-2023 04:25:17
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions