In: Computer Science
package newone;
import java.util.Date;
public class DateExample {
public static void main(String[] args) {
Date d = new Date();
String[] months =
{"January","February","March","April","May","June","July","August","September","October","November","December"};
System.out.println("Current month:
"+d.getMonth());//month starts from 0 to 11, so for October, it
will be 9
System.out.println("Current month:
"+months[d.getMonth()]);
System.out.println("Current year:
"+(d.getYear()+1900));//you need to add 1900 to year as getYear
returns year - 1900
}
}