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:MainClass.java
public static void main(String args[]) { GregorianCalendar today = new GregorianCalendar(); int todayMonth = today.get(Calendar.MONTH); int todayDayOfMonth = today.get(Calendar.DAY_OF_MONTH); int todayYear = today.get(Calendar.YEAR); int todayDayOfYear = today.get(Calendar.DAY_OF_YEAR); int numDays;/* w w w . j a va 2s. c om*/ if (todayMonth == 11 && todayDayOfMonth > 25) { GregorianCalendar xmas = new GregorianCalendar(todayYear + 1, 11, 25); int xmasDayOfYear = xmas.get(Calendar.DAY_OF_YEAR); numDays = xmasDayOfYear + 31 - todayDayOfMonth; } else { GregorianCalendar xmas = new GregorianCalendar(todayYear, 11, 25); int xmasDayOfYear = xmas.get(Calendar.DAY_OF_YEAR); numDays = xmasDayOfYear - todayDayOfYear; } System.out.println("The number of days till Christmas is " + numDays); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = new GregorianCalendar(1999, 1, 1); Calendar now = new GregorianCalendar(); int res = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR); if ((cal.get(Calendar.MONTH) > now.get(Calendar.MONTH)) || (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH) && cal.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH))) { res--;//from ww w .j a va2 s . c om } System.out.println(res); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the value of all the calendar date fields. System.out.println("Calendar's Year: " + cal.get(Calendar.YEAR)); System.out.println("Calendar's Month: " + cal.get(Calendar.MONTH)); System.out.println("Calendar's Day: " + cal.get(Calendar.DATE)); }
From source file:Main.java
public static void main(String[] args) { Date today = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(today);/*from ww w.j a va 2s. c o m*/ calendar.add(Calendar.MONTH, 1); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.add(Calendar.DATE, -1); Date lastDayOfMonth = calendar.getTime(); DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); System.out.println("Today : " + sdf.format(today)); System.out.println("Last Day of Month: " + sdf.format(lastDayOfMonth)); }
From source file:Main.java
public static void main(String[] args) { String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; Calendar cal = Calendar.getInstance(); String month = months[cal.get(Calendar.MONTH)]; System.out.println("Month name: " + month); }
From source file:MainClass.java
public static void main(String[] args) { // get a calendar using the default time zone and locale. Calendar calendar = Calendar.getInstance(); // set Date portion to January 1, 1970 calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DATE, 1); // normalize the object calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); }
From source file:Main.java
public static void main(String[] args) { String[] monthName = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; Calendar cal = Calendar.getInstance(); String month = monthName[cal.get(Calendar.MONTH)]; System.out.println("Month name: " + month); }
From source file:Main.java
public static void main(String[] args) { GregorianCalendar gc = new GregorianCalendar(); // current year value int year = gc.get(Calendar.YEAR); System.out.println(year);/*from w w w .j ava 2 s. c o m*/ // current month value int month = gc.get(Calendar.MONTH); System.out.println(month); // day of month int day = gc.get(Calendar.DAY_OF_MONTH); System.out.println(day); // hour value int hour = gc.get(Calendar.HOUR); System.out.println(hour); // minute value int minute = gc.get(Calendar.MINUTE); System.out.println(minute); // second values int second = gc.get(Calendar.SECOND); System.out.println(second); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // return the maximum value for days int max = cal.getMaximum(Calendar.DAY_OF_WEEK); System.out.println("Maximum days :" + max); // return the maximum value for months max = cal.getMaximum(Calendar.MONTH); System.out.println("Maximum months :" + max); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the maximum value that year field can have int i = cal.getActualMaximum(Calendar.YEAR); System.out.println("Maximum year:" + i); // get the maximum value that month field can have int a = cal.getActualMaximum(Calendar.MONTH); System.out.println("Maximum month:" + a); }