Print Time Example Java Program


Syntax

GregorianCalendar Variable_name1 = new GregorianCalendar();
Variable_name2 = date.get(Calendar.SECOND);
Variable_name3 = date.get(Calendar.MINUTE);
Variable_name4 = date.get(Calendar.HOUR);

Print Time Example Program

import java.util.*;
 
class PrintTime{
	public static void main(String args[]){
		int day, month, year;
		int second, minute, hour;
		GregorianCalendar date = new GregorianCalendar();
		second = date.get(Calendar.SECOND);
		minute = date.get(Calendar.MINUTE);
		hour = date.get(Calendar.HOUR);
		System.out.println("Current time is  "+hour+" : "+minute+" : "+second);
	}
}	

Sample Output

Output is:
Current time is  1 : 2 : 28