Write a Java Program to Get current system date and time in Java


  • import java.util.Date;: This line imports the Date class from the java.util package. This class represents a specific instant in time, with millisecond precision.
  • public class Current_SystemDate: This line declares a public class called Current_SystemDate.
  • public static void main(String args[]): This line declares the main method, which is the entry point of the program. It takes a single argument, which is an array of strings.
  • Date dt = new Date();: This line creates a new Date object called dt, which represents the current date and time.
  • System.out.print("Current System Date and Time : " + dt.toString());: This line prints out the string "Current System Date and Time : " concatenated with the result of calling the toString() method on the dt object. The toString() method returns a string representation of the date and time in a human-readable format.

Source Code

import java.util.Date;
public class Current_SystemDate
{
	public static void main(String args[])
	{
		Date dt = new Date();
		System.out.print("Current System Date and Time : " + dt.toString());
	}
}

Output

Current System Date and Time : Sat Dec 17 14:44:31 IST 2022

Example Programs