List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:org.mifos.framework.util.helpers.DateUtils.java
public static Date getLastDayOfNextYear() { Calendar cal = getCurrentDateCalendar(); cal.set(Calendar.MONTH, Calendar.DECEMBER); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE)); Calendar cal1 = getCurrentDateCalendar(); cal1.set(cal.get(Calendar.YEAR) + 1, cal.get(Calendar.MONTH), cal.get(Calendar.DATE), 0, 0, 0); return cal1.getTime(); }
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static Calendar getLastDayOfYearAfterNextYear() { Calendar cal = getCurrentDateCalendar(); cal.set(Calendar.MONTH, Calendar.DECEMBER); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE)); Calendar cal1 = getCurrentDateCalendar(); cal1.set(cal.get(Calendar.YEAR) + 2, cal.get(Calendar.MONTH), cal.get(Calendar.DATE), 0, 0, 0); return cal1;//from ww w .j a v a2 s . co m }
From source file:com.camel.framework.utils.DateUtils.java
/** * ?/*from w w w . j a v a2s . c o m*/ * * @param day day of month * @return */ public static String getConfirmMonthDayDateString(Integer day) { Calendar objCal = Calendar.getInstance(); Date date = new Date(); objCal.setTime(date); objCal.set(Calendar.MONTH, objCal.get(Calendar.MONTH) - 1); if (day != DAY_31) { objCal.set(Calendar.DAY_OF_MONTH, day); } else { objCal.set(Calendar.DAY_OF_MONTH, objCal.getActualMaximum(Calendar.DAY_OF_MONTH)); } return getStandardDate(objCal.getTime()); }
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 w w w . j a v a 2 s.c om 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; }
From source file:com.swiftcorp.portal.common.util.CalendarUtils.java
@Deprecated public static Calendar addMonthDayToCal(Calendar cal, int month, int day) { Date d = new Date(); int daysToAdd = 0; // Calendar cal = Calendar.getInstance(); int currentMonth = cal.get(2); long t = 0;/* w ww. j av a 2 s . com*/ t = d.getTime(); if (month > 0) { // cal.get ( month ); for (int i = 0; i < month; i++) { if (currentMonth < 12) { if (currentMonth == Calendar.JANUARY) { cal.set(2, Calendar.JANUARY); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.FEBRUARY) { cal.set(2, Calendar.FEBRUARY); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.MARCH) { cal.set(2, Calendar.MARCH); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.APRIL) { cal.set(2, Calendar.APRIL); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.MAY) { cal.set(2, Calendar.MAY); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.JUNE) { cal.set(2, Calendar.JUNE); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.JULY) { cal.set(2, Calendar.JULY); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.AUGUST) { cal.set(2, Calendar.AUGUST); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.SEPTEMBER) { cal.set(2, Calendar.SEPTEMBER); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.OCTOBER) { cal.set(2, Calendar.OCTOBER); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.NOVEMBER) { cal.set(2, Calendar.NOVEMBER); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } else if (currentMonth == Calendar.DECEMBER) { cal.set(2, Calendar.DECEMBER); daysToAdd += cal.getActualMaximum(Calendar.DAY_OF_MONTH); } currentMonth++; } else { currentMonth = 0; i--; } } } daysToAdd += day; // add the desired number of days to the long value using milli seconds t += daysToAdd * MILLIS_PER_DAY; cal.setTime(new Date(t)); // and now you can format the date the way you want String result = Integer.toString(cal.get(Calendar.DAY_OF_MONTH)) + "-" + Integer.toString(cal.get(Calendar.MONTH) + 1) + "-" + Integer.toString(cal.get(Calendar.YEAR)); System.out.println("result month add::" + result); return cal; }
From source file:org.apache.lens.cube.parse.DateUtil.java
public static CoveringInfo getWeeklyCoveringInfo(Date from, Date to) { int dayDiff = 0; Date tmpFrom = from;// ww w. j av a 2s . c om while (tmpFrom.before(to)) { tmpFrom = DateUtils.addDays(tmpFrom, 1); dayDiff++; } if (dayDiff < 7) { return new CoveringInfo(0, false); } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromWeek = cal.get(Calendar.WEEK_OF_YEAR); int fromDay = cal.get(Calendar.DAY_OF_WEEK); int fromYear = cal.get(YEAR); cal.clear(); cal.set(YEAR, fromYear); cal.set(Calendar.WEEK_OF_YEAR, fromWeek); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); int maxDayInWeek = cal.getActualMaximum(Calendar.DAY_OF_WEEK); Date fromWeekStartDate = cal.getTime(); boolean coverable = dayDiff % 7 == 0; if (fromWeekStartDate.before(from)) { // Count from the start of next week dayDiff -= (maxDayInWeek - (fromDay - Calendar.SUNDAY)); coverable = false; } return new CoveringInfo(dayDiff / 7, coverable); }
From source file:Dates.java
/** * Whether the given date in the specified TimeZone is the last day of that * month. If TimeZone is null, meaning use default TimeZone of the JVM. *//*from ww w . ja v a 2 s . c om*/ final public static boolean isEndOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); // don't call cal.setTime(Date) which // will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); final int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); return day == maxDay; }
From source file:com.gnizr.core.util.GnizrDaoUtil.java
/** * Returns a <code>Date</code> object that represents the ending * hour,min,second of a day (i.e., 23:59:59). The returned object shares the * same year, month, day values as the input <code>date</code> * //from w ww .j a va 2s.co m * @param date * an instantiated date * @return the ending hour/min/sec of <code>date</code> */ public static Date toDayEnds(Date date) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND)); return cal.getTime(); }
From source file:Dates.java
/** * Given a date, a proper TimeZone, return the ending date of the month of the * specified date and TimeZone. If TimeZone is null, meaning use default * TimeZone of the JVM.//from w w w .j a v a2s . co m */ final public static Date endOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); // don't call cal.setTime(Date) which // will reset the TimeZone. final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); final int monthDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.clear(); cal.set(year, month, monthDays + 1); cal.setTimeInMillis(cal.getTimeInMillis() - 1); return cal.getTime(); }
From source file:com.sammyun.util.DateUtil.java
/** * /* w w w.ja va2s . c o m*/ * * @param year String * @return day int */ public static int getDayFromYear(String year) { SimpleDateFormat format = new SimpleDateFormat(year_format); Date date; int day = 0; try { date = format.parse(year); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); day = calendar.getActualMaximum(Calendar.DAY_OF_YEAR); } catch (ParseException e) { e.printStackTrace(); } return day; }