Date and Format
Creating and Using Date Objects:
Date Objects:import java.util.Date;
public class DateExample {
public static void main(String[] args) {
Date currentDate = new Date(); // Current date and time
System.out.println("Current Date and Time: " + currentDate);
}
}import java.util.Date;
import java.text.SimpleDateFormat;
public class DateFormattingExample {
public static void main(String[] args) {
Date currentDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String formattedDate = sdf.format(currentDate);
System.out.println("Formatted Date and Time: " + formattedDate);
}
}Important Points about Date Class:
Date Class:Example Using java.time Package (Java 8+):
java.time Package (Java 8+):Last updated