Print System Date and Time in Java Programming
Here’s a Simple Code To Print System Date and Time in Java Programming Language. This Java Program prints the Current Date and Time of the System that you’re logged in to. Hence, it may be different than the Actual Time if your System is configured to a different Time and Date Zone.
About The Program
This Java Program uses GregorianCalendar Class from java.util Package. There are several methods declared within the GregorianCalendar Class that provides Year, Hour, Second, Minute, Day and Month of the Year.
GregorianCalendar is a Subclass of Calendar Class that provides Standard Calendar System. The format of this Class is as follows:
public class GregorianCalendar extends Calendar
Code To Print System Date and Time in Java Programming
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import java.io.*; import java.util.*; class DateAndTimeValues { public static void main(String arguments[]) { int Year, Month, Day; int Hour, Minute, Second; GregorianCalendar DateObject = new GregorianCalendar(); Year = DateObject.get(Calendar.YEAR); Month = DateObject.get(Calendar.MONTH); Day = DateObject.get(Calendar.DAY_OF_MONTH); Hour = DateObject.get(Calendar.HOUR); Minute = DateObject.get(Calendar.MINUTE); Second = DateObject.get(Calendar.SECOND); System.out.println("\nSystem Date: " + Day + "/" + (Month + 1) + "/" + Year); System.out.println("\nSystem Time: " + Hour + ":" + Minute + ":" + Second + "\n"); } } |
Also Read: Java Code To Check Public IP Address
Output

In case you get any Compilation Errors with this Java Program To Display System Date and Time or you have any doubt about it, mention it in the Comment Section.