List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:com.netsteadfast.greenstep.util.SimpleUtils.java
public static int getMaxDayOfMonth(final int year, final int month) { int max = 28; Calendar calendar = Calendar.getInstance(); if (year >= 1900 && year <= 3000) { calendar.set(Calendar.YEAR, year); } else {/*from w w w .ja v a2 s.c o m*/ calendar.set(Calendar.YEAR, 1900); } if (month >= 1 && month <= 12) { calendar.set(Calendar.MONTH, (month - 1)); } else { calendar.set(Calendar.MONTH, 0); } calendar.set(Calendar.DATE, 1); max = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); return max; }
From source file:com.glaf.core.util.DateUtils.java
/** * ?//from w w w . j a va2s . c o m * * @param startDate * @param endDate * @return */ public static int getDaysBetween(Calendar startDate, Calendar endDate) { if (startDate.after(endDate)) { java.util.Calendar swap = startDate; startDate = endDate; endDate = swap; } int days = endDate.get(java.util.Calendar.DAY_OF_YEAR) - startDate.get(java.util.Calendar.DAY_OF_YEAR); int y2 = endDate.get(java.util.Calendar.YEAR); if (startDate.get(java.util.Calendar.YEAR) != y2) { startDate = (java.util.Calendar) startDate.clone(); do { days += startDate.getActualMaximum(java.util.Calendar.DAY_OF_YEAR); startDate.add(java.util.Calendar.YEAR, 1); } while (startDate.get(java.util.Calendar.YEAR) != y2); } return days; }
From source file:Dates.java
/** * Difference of 2 dates in years, months and days. <p> * //from w w w. java2 s . c om * @param f1 If null returns null * @param f2 If null returns null */ public static DateDistance dateDistance(java.util.Date f1, java.util.Date f2, boolean includeStartDate) { DateDistance df = new DateDistance(); if (null == f1 || null == f2) return null; Calendar fmax = Calendar.getInstance(), fmin = Calendar.getInstance(); f1 = Dates.removeTime(f1); f2 = Dates.removeTime(f2); if (f1.after(f2)) { fmax.setTime(f1); fmin.setTime(f2); } else { fmin.setTime(f1); fmax.setTime(f2); } int initDay = fmin.get(Calendar.DATE); int initMonth = fmin.get(Calendar.MONTH); int initYear = fmin.get(Calendar.YEAR); int endMonth = fmax.get(Calendar.MONTH); int endYear = fmax.get(Calendar.YEAR); int finalLimit = fmax.getActualMaximum(Calendar.DATE); int initPeak = 0; int finalPeak = 0; if (initMonth == endMonth && initYear == endYear) { while (fmin.getTime().before(fmax.getTime())) { fmin.add(Calendar.DATE, 1); df.days++; } if (includeStartDate) { df.days++; } if (df.days >= finalLimit) { df.months++; df.days = 0; } return df; } if (initDay != 1) { while (fmin.get(Calendar.DATE) != 1) { fmin.add(Calendar.DATE, 1); initPeak++; } } while (fmin.get(Calendar.MONTH) != endMonth || fmin.get(Calendar.YEAR) != endYear) { fmin.add(Calendar.MONTH, 1); df.months++; if (df.months == 12) { df.years++; df.months = 0; } } while (fmin.getTime().before(fmax.getTime())) { fmin.add(Calendar.DATE, 1); finalPeak++; } int peak = initPeak + finalPeak; if (includeStartDate) { peak++; } if (peak >= finalLimit) { peak = peak - finalLimit; df.months++; if (df.months == 12) { df.years++; df.months = 0; } } df.days = peak; return df; }
From source file:com.huateng.ebank.framework.util.DateUtil.java
/** * ?//from ww w .j a v a2 s. c o m * * @param today * @return */ public static Date getLastDate(Date today) { Calendar calendar = Calendar.getInstance(); calendar.setTime(today); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); return calendar.getTime(); }
From source file:org.power.commons.lang.util.time.DateUtils.java
/** * #func ???<br>/*ww w . j a v a2 s. c o m*/ * * @author dulin */ public static Date getLastDayOfMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int firstDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); return org.apache.commons.lang3.time.DateUtils.setDays(date, firstDay); }
From source file:com.sammyun.util.DateUtil.java
/** * ?? ??? 2012-01-01?/* w ww .jav a2 s . co m*/ * * @param date ? YY-MM * @param isEnd ? * @return * @see [?#?#?] */ public static String parseEarlyEndMonth(String date, boolean isEnd) { // ? if (!isEnd) { return date.concat("-01"); } else { String[] yearMonths = date.split("-"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.valueOf(yearMonths[0])); cal.set(Calendar.MONTH, Integer.valueOf(yearMonths[1]) - 1); // ? Integer maxDate = cal.getActualMaximum(Calendar.DATE); return date.concat("-".concat(maxDate.toString())); } }
From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilter.java
@Override protected void adjustExpires(Calendar next) { if (StringUtils.equalsIgnoreCase(LAST, dayOfMonth)) { next.set(Calendar.DAY_OF_MONTH, next.getActualMaximum(Calendar.DAY_OF_MONTH)); } else {/*from w w w .j av a 2 s . c om*/ next.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dayOfMonth)); } if (next.before(Calendar.getInstance())) { next.add(Calendar.MONTH, 1); } }
From source file:com.huateng.ebank.framework.util.DateUtil.java
/** * ?/*from w ww . ja va2 s. c o m*/ * * @param today * @return */ public static Date getNextLastDate(Date today) { Calendar calendar = Calendar.getInstance(); calendar.setTime(getNextDay(getLastDate(today))); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); return calendar.getTime(); }
From source file:com.timesheet.data.BookingImp.java
@Override public List<Booking> getBookingByUserAndMonth(Integer userId, Integer month) { Calendar currentCal = Calendar.getInstance(); currentCal.set(Calendar.MONTH, month); int lastDayOfMonth = currentCal.getActualMaximum(Calendar.DAY_OF_MONTH); currentCal.set(Calendar.DAY_OF_MONTH, 1); Date startDate = currentCal.getTime(); System.out.println("@@@@@@@@@@@@@@@@Start of month :" + startDate); currentCal.set(Calendar.DAY_OF_MONTH, lastDayOfMonth); Date endDate = currentCal.getTime(); System.out.println("@@@@@@@@@@@@@@@@Start of month :" + endDate); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. return sessionFactory.getCurrentSession().createQuery( "from Booking where bookingDate >= :startDate AND bookingDate <= :endDate AND userId = :userId") .setDate("startDate", startDate).setDate("endDate", endDate).setInteger("userId", userId).list(); }
From source file:org.power.commons.lang.util.time.DateUtils.java
/** * ??? 20081231 -1 20081130/*from ww w.j a va 2s .co m*/ * * @param dt * @param n * @return?11:16:22 */ public static Date getNextMonth(Date dt, Long n) { Calendar cal = new GregorianCalendar(); cal.setTime(dt); Calendar firstCal = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue(), 1); if (firstCal.getActualMaximum(Calendar.DAY_OF_MONTH) < cal.get(Calendar.DAY_OF_MONTH)) { return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue(), firstCal.getActualMaximum(Calendar.DAY_OF_MONTH)).getTime(); } else { return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue(), cal.get(Calendar.DAY_OF_MONTH)).getTime(); } }