JAVA Program to calculate age by entering Date Of Birth (DOB)

// checking current date and time and formatting it
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class currentDate {

public static void main(String args[]) {

LocalDateTime dateTime = LocalDateTime.now();

System.out.print("Before Formatting: " +dateTime);

//DateTimeFormatter
//Formatter for printing and parsing date-time objects.
//This class provides the main application entry point for printing and parsing and provides
// common implementations of DateTimeFormatter:
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");

String formattedDate = dateTime.format(dateTimeFormatter);

System.out.println("\nAfter formatting:" +formattedDate);
}
}

1 Comments

Previous Post Next Post

Contact Form