List of usage examples for java.util Calendar MONTH
int MONTH
To view the source code for java.util Calendar MONTH.
Click Source Link
get
and set
indicating the month. From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // display the current calendar System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll month cal.roll(Calendar.MONTH, 2);//ww w.ja v a 2s.c om // print result after rolling System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll downwards cal.roll(Calendar.MONTH, -4); // print result System.out.println("Month is " + cal.get(Calendar.MONTH)); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // displays the current calendar System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll month cal.roll(Calendar.MONTH, true); // print result after rolling System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll downwards cal.roll(Calendar.MONTH, false); // print result after rolling down System.out.println("Month is " + cal.get(Calendar.MONTH)); }
From source file:MainClass.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println(calendar.get(Calendar.YEAR)); System.out.println(calendar.get(Calendar.MONTH)); System.out.println(calendar.get(Calendar.DATE)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.MINUTE)); System.out.println(calendar.get(Calendar.SECOND)); System.out.println(calendar.get(Calendar.MILLISECOND)); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the days required in the first week of the year System.out.println("Months required: " + cal.get(Calendar.MONTH)); // print the lowest maximum months for year. int max = cal.getLeastMaximum(Calendar.MONTH); System.out.println("Lowest maximum months :" + max); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now.getTime()); int month = now.get(Calendar.MONTH); if (month == Calendar.JANUARY) { System.out.println("JANUARY"); }/*from w w w.j a va 2 s . co m*/ if (month == Calendar.FEBRUARY) { System.out.println("FEBRUARY"); } if (month == Calendar.MARCH) { System.out.println("MARCH"); } if (month == Calendar.APRIL) { System.out.println("APRIL"); } if (month == Calendar.MAY) { System.out.println("MAY"); } if (month == Calendar.JUNE) { System.out.println("JUNE"); } if (month == Calendar.JULY) { System.out.println("JULY"); } if (month == Calendar.AUGUST) { System.out.println("AUGUST"); } if (month == Calendar.SEPTEMBER) { System.out.println("SEPTEMBER"); } if (month == Calendar.OCTOBER) { System.out.println("OCTOBER"); } if (month == Calendar.NOVEMBER) { System.out.println("NOVEMBER"); } if (month == Calendar.DECEMBER) { System.out.println("DECEMBER"); } }
From source file:KVMCalendar.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Date date = new Date(); cal.setTime(date);//from w w w.j a va 2 s . c o m int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("Day is " + day + ", month is " + month); final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L; long offset = date.getTime(); offset += 20 * MILLIS_PER_DAY; date.setTime(offset); cal.setTime(date); month = cal.get(Calendar.MONTH); day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("In 20 days time, day will " + day + ", month will be " + month); System.out.println(cal); }
From source file:Main.java
public static void main(String[] args) { Calendar futureCal = Calendar.getInstance(); futureCal.set(Calendar.YEAR, 3000); Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); System.out.println("Is futureCal after now ? : " + futureCal.after(now)); }
From source file:Main.java
public static void main(String[] args) { int year = 2009; int month = 0; // January int date = 1; Calendar cal = Calendar.getInstance(); cal.clear();//from w w w . j ava2 s. com cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); java.util.Date utilDate = cal.getTime(); System.out.println(utilDate); }
From source file:Main.java
public static void main(String[] args) { int year = 2009; int month = 0; // January int date = 1; Calendar cal = Calendar.getInstance(); cal.clear();/* w w w. ja va 2s . c o m*/ cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis()); System.out.println(sqlDate); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); // //from w w w . j a v a 2s.co m System.out.println("Current Year is : " + now.get(Calendar.YEAR)); // month start from 0 to 11 System.out.println("Current Month is : " + (now.get(Calendar.MONTH) + 1)); System.out.println("Current Date is : " + now.get(Calendar.DATE)); }