Java Program to Display Current Date and Time
import java.util.*;
public class Main
{
public static void main(String[] args)
{
// Create object of Formatter as ‘f’
Formatter f = new Formatter();
// Declare a variable ‘cal’ of type Calendar
//and initialize it to get the system date-time using Calender.getInstance() method
Calendar cal = Calendar.getInstance();
// using inbuild method of formatter class .format("%tc", cal) we can get the current date and time format
f.format("%tc", cal);
//print the result
System.out.println("The current date and time is: "+f);
}
}
Output:
The current date and time is: Sun Jun 26 07:39:14 GMT 2022
