Intro
This examples, will demonstrates how to display month of the year using java Calendar class.
Examples
package com.freesamplecode.java.datetime; import java.util.Calendar; public class GetMonthOfYearDemo { public static void main(String[] args){ Calendar cal = Calendar.getInstance(); System.out.println("Current Date (mm-dd-yyy) is : "+(cal.get(Calendar.MONTH)+1) +"-"+cal.get(Calendar.DATE) +"-"+cal.get(Calendar.YEAR)); String[] monthOfYear = new String[]{"January", "February", "March", "April" , "May","June","July","August","September","October","November","December"}; System.out.println("Current Month is : "+monthOfYear[cal.get(Calendar.MONTH)]); } }
Output
Current Date (mm-dd-yyy) is : 3-17-2016 Current Month is : March
0 comments: