Write a program to print month of the year in Java with output

 

import java.util.Calendar;
public class Month{
public static void main(String[] args)
{
Calendar now = Calendar.getInstance();
System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1)
+ "-"
+ now.get(Calendar.DATE)
+ "-"
+ now.get(Calendar.YEAR));
String[] strMonths = new String[]
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
System.out.println("Current month is : " +
strMonths[now.get(Calendar.MONTH)]
);
}
}

 

Output:

Write a program to print month of the year in Java with output

Leave a Reply

Your email address will not be published. Required fields are marked *