Get current Date and Time in java

import java.util.Calendar;
import java.util.Date;

public class DateTimeExample {
	public static void main(String[] args) {

		// Using java.util.Date
		System.out.println("Today Date using Date class..");
		Date date = new Date();
		System.out.println("Date : "+date);

		// Using java.util.Calendar
		System.out.println("\nToday Date and Time using Calendar class..");
		Calendar calendar = Calendar.getInstance();
		
		System.out.println("Date :  " + calendar.getTime());
		System.out.println("Day  : " + calendar.get(Calendar.DAY_OF_MONTH));
		System.out.println("Month: " + calendar.get(Calendar.MONTH));
		System.out.println("Time : " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
				+ calendar.get(Calendar.MINUTE) + ":"
				+ calendar.get(Calendar.SECOND));

	}

}
Output
Today Date using Date class.. Date : Mon Oct 05 16:05:36 IST 2015 Today Date and Time using Calendar class.. Date : Mon Oct 05 16:05:36 IST 2015 Day : 5 Month: 9 Time : 16:5:36










Related Examples


Write a program to get list of all the files from a given directory?
Write a Comparator to compare students based upon their name and age?
Simple Array Sorting Program.
Bubble Sort Example.
Write a java program to check if a number is Armstrong number or not?








Receive Latest Java Examples in Your Email: