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 String getMonthStringFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w w w. j a va2 s. c o m StringBuilder sb = new StringBuilder(); sb.append(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.US)).append(", ") .append(calendar.get(Calendar.YEAR)); return sb.toString(); }
From source file:Main.java
public static int getYears(int year, int month, int day) { GregorianCalendar cal = new GregorianCalendar(); int y, m, d, noofyears; y = cal.get(Calendar.YEAR);// current year , m = cal.get(Calendar.MONTH);// current month d = cal.get(Calendar.DAY_OF_MONTH);//current day cal.set(year, month, day);// here ur date noofyears = y - cal.get(Calendar.YEAR); if ((m < cal.get(Calendar.MONTH)) || ((m == cal.get(Calendar.MONTH)) && (d < cal.get(Calendar.DAY_OF_MONTH)))) { --noofyears;/*from w w w . j a v a 2s . co m*/ } try { if (noofyears < 0) throw new IllegalArgumentException("age < 0"); } catch (IllegalArgumentException ile) { ile.printStackTrace(); } System.out.println(noofyears); return noofyears; }
From source file:Main.java
public static long betweenMonth(String t1, String t2, String... patterns) { return betweenTime(Calendar.YEAR, t1, t2, patterns) * 12 + betweenTime(Calendar.MONTH, t1, t2, patterns); }
From source file:Main.java
/** * Return if the two calendar is in the same day, ignoring time * @param day1/* w w w . j a va2 s . c om*/ * @param day2 * @return */ public static boolean isSameDay(Calendar day1, Calendar day2) { return day1.get(Calendar.YEAR) == day2.get(Calendar.YEAR) && day1.get(Calendar.MONTH) == day2.get(Calendar.MONTH) && day1.get(Calendar.DAY_OF_MONTH) == day2.get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
public static String dateToString(String dateString) { Calendar date = Calendar.getInstance(); date.setTimeInMillis((long) Integer.parseInt(dateString) * 1000); return date.get(Calendar.DAY_OF_MONTH) + "/" + String.format("%02d", date.get(Calendar.MONTH) + 1); }
From source file:Main.java
public static int getSeason(Calendar calendar) { int month = calendar.get(Calendar.MONTH) + 1; switch (month) { case 1://from w ww .j a v a2s. c om case 11: case 12: return SEASON_SPRING; case 2: case 3: case 4: return SEASON_SUMMER; case 5: case 6: case 7: return SEASON_AUTUMN; case 8: case 9: case 10: return SEASON_WINTER; } return SEASON_SPRING; }
From source file:Main.java
public static Date firstDateOfNextMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from ww w. ja va 2 s . co m*/ calendar.add(Calendar.MONTH, 1); Date newDate = calendar.getTime(); return firstDateOfMonth(newDate); }
From source file:Main.java
public static String getLastDayOfThisMonth() { String str = ""; Calendar lastDate = Calendar.getInstance(); lastDate.set(Calendar.DATE, 1);// lastDate.add(Calendar.MONTH, 1);// lastDate.add(Calendar.DATE, -1);// str = sdf.format(lastDate.getTime()); return str;// w ww.j a v a2 s. c o m }
From source file:Main.java
public static String getNowDataForChart() { Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); return month + "-" + day; }
From source file:Main.java
public static Calendar getRandomApodDate() { Calendar newCalendar = Calendar.getInstance(); Calendar today = Calendar.getInstance(); int currentYear = today.get(Calendar.YEAR); int currentMonth = today.get(Calendar.MONTH); int currentDay = today.get(Calendar.DATE); int firstApodYear = 1995; int firstApodMonth = 5; int firstApodDay = 20; Random rnd = new Random(); int newYear = rnd.nextInt(currentYear - firstApodYear + 1) + firstApodYear; int minMonth = 0; int maxMonth = 11; if (newYear == firstApodYear) minMonth = firstApodMonth;/*from ww w .j a v a 2s. co m*/ if (newYear == currentYear) maxMonth = currentMonth; int newMonth = rnd.nextInt(maxMonth - minMonth + 1) + minMonth; newCalendar.set(newYear, newMonth, 1); int minDay = 1; int maxDay = newCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); if (newYear == firstApodYear && newMonth == firstApodMonth) minDay = firstApodDay; if (newYear == currentYear && newMonth == currentMonth) maxDay = currentDay; int newDay = rnd.nextInt(maxDay - minDay + 1) + minDay; newCalendar.set(newYear, newMonth, newDay); return newCalendar; }