Print Date Example Java Program


Syntax

GregorianCalendar Variable_name1 = new GregorianCalendar();
Variable_name2 = date.get(Calendar.DAY_OF_MONTH);
Variable_name3 = date.get(Calendar.MONTH);
Variable_name4 = date.get(Calendar.YEAR);

Print Date Example Program

import java.util.*;

class PrintDate{
	public static void main(String args[]){
		int day, month, year;
		GregorianCalendar date = new GregorianCalendar();
		day = date.get(Calendar.DAY_OF_MONTH);
		month = date.get(Calendar.MONTH);
		year = date.get(Calendar.YEAR);
		System.out.println("Current date is  "+day+"/"+(month+1)+"/"+year);
	}
}	

Sample Output

Output is:
Current date is  5/5/2015