How to get current date and current month in Java

We can get the current date from the Calendar class as given below.
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));
This will print 20/11/2013

And if you want month name from the date follow the below given code
ystem.out.println(new SimpleDateFormat("MMMM").format(cal.getTime()));
Prints November

Full code given below;
public class TesC {
public static void main(String args[]){
String today = (new Date()).toString();
System.out.println(today);
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));
System.out.println(new SimpleDateFormat("MMMM").format(cal.getTime()));

}
}
output
Wed Nov 20 13:42:33 GST 2013
20/11/2013
November

Comments