List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:org.apache.lens.cube.parse.DateUtil.java
public static int getNumberofDaysInMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//w ww .ja va2 s . co m return calendar.getActualMaximum(DAY_OF_MONTH); }
From source file:nl.strohalm.cyclos.utils.DateHelper.java
public static Period[] getPeriodsThroughTheTime(final Period period, final ThroughTimeRange throughTimeRange) { final Calendar calendarIni = period.getBegin(); final Calendar calendarFini = period.getEnd(); final List<Period> result = new ArrayList<Period>(); final int monthIni = calendarIni.get(Calendar.MONTH); final int monthFini = calendarFini.get(Calendar.MONTH); final int yearIni = calendarIni.get(Calendar.YEAR); final int yearFini = calendarFini.get(Calendar.YEAR); for (int year = calendarIni.get(Calendar.YEAR); year <= calendarFini.get(Calendar.YEAR); year++) { Period periodAux = null;/*w w w . jav a 2 s .c o m*/ int monthIniAux = 0; int monthFiniAux = 11; if (year == yearIni) { monthIniAux = monthIni; } else { monthIniAux = 0; } if (year == yearFini) { monthFiniAux = monthFini; } else { monthFiniAux = 11; } int increment = 1; // months or quarters if (throughTimeRange == ThroughTimeRange.MONTH || throughTimeRange == ThroughTimeRange.QUARTER) { // only quarters if (throughTimeRange == ThroughTimeRange.QUARTER) { increment = 3; } for (int month = monthIniAux; month <= monthFiniAux; month = month + increment) { final Calendar calendarIniAux = new GregorianCalendar(year, month, 1, 0, 0, 0); final Calendar calendarFiniHlp = new GregorianCalendar(year, (month + increment - 1), 1); final Calendar calendarFiniAux = new GregorianCalendar(year, (month + increment - 1), calendarFiniHlp.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59); periodAux = new Period(calendarIniAux, calendarFiniAux); result.add(periodAux); } } // years, it doesn't need to iterate over months. else if (throughTimeRange == ThroughTimeRange.YEAR) { final Calendar calendarIniAux = new GregorianCalendar(year, 0, 1, 0, 0, 0); final Calendar calendarFiniAux = new GregorianCalendar(year, 11, 31, 23, 59, 59); periodAux = new Period(calendarIniAux, calendarFiniAux); result.add(periodAux); } } final Period[] periodResult = new Period[result.size()]; return result.toArray(periodResult); }
From source file:com.bjorsond.android.timeline.utilities.Utilities.java
public static Date getLastDayOfMonth(Date dateInMonth) { Calendar calendar = Calendar.getInstance(); calendar.setTime(dateInMonth);//from ww w .j a v a2 s . c o m int lastDate = calendar.getActualMaximum(Calendar.DATE); calendar.clear(); calendar.set(Calendar.DATE, lastDate); return calendar.getTime(); }
From source file:com.apextom.util.DateUtil.java
/** * ?./*from w ww . jav a2 s . c o m*/ * * @param date * @return */ public static int getMonthMaxDay(Date date) { if (date == null) { return -1; } Calendar cal = new GregorianCalendar(); cal.setTime(date); return cal.getActualMaximum(Calendar.DATE); }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
public static Date getDateBefore(int before) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -before); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY)); return cal.getTime(); }
From source file:br.msf.commons.util.AbstractDateUtils.java
public static Integer getLastDayOfMonth(final Object date) { ArgumentUtils.rejectIfNull(date);//from w w w.j av a 2 s. com Calendar c = castToCalendar(date); return c.getActualMaximum(Calendar.DAY_OF_MONTH); }
From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java
/** * /*www. j a v a2 s.c o m*/ * * @param date * yyyy-MM * @return * @author lixiang * @throws ParseException * @create 2008-9-22 01:59:33 * @since */ public static List getDatesList(String date) throws ParseException { DateFormat format = new SimpleDateFormat("yyyy-MM"); Calendar time = Calendar.getInstance(); time.clear(); Date d1 = format.parse(date); time.setTime(d1); int day = time.getActualMaximum(Calendar.DAY_OF_MONTH); DateFormat formats = new SimpleDateFormat(Defines.FORMAT_DATE_STRING); List list = new ArrayList(); for (int i = 1; i <= day; i++) { String s = format.format(d1) + "-" + i; Date sss = formats.parse(s); String dd = formats.format(sss); list.add(dd); } return list; }
From source file:de.mpg.escidoc.services.reporting.ReportFHI.java
public static String[] getStartEndDateOfQuery() { SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-"); int months;/*w w w. j a va 2s . co m*/ try { months = new Integer(rprops.getProperty("FHI.report.months.range")).intValue(); } catch (Exception e) { throw new RuntimeException("Cannot read/convert FHI.report.months.range:", e); } ; //from Calendar fromMonth = GregorianCalendar.getInstance(); fromMonth.add(Calendar.MONTH, -months); String fromYearMonth = dateformatter.format(fromMonth.getTime()); //to Calendar toMonth = GregorianCalendar.getInstance(); toMonth.add(Calendar.MONTH, -1); String toYearMonth = dateformatter.format(toMonth.getTime()); return new String[] { fromYearMonth + String.format("%02d", fromMonth.getActualMinimum(Calendar.DAY_OF_MONTH)), toYearMonth + toMonth.getActualMaximum(Calendar.DAY_OF_MONTH) }; }
From source file:de.mpg.mpdl.inge.reporting.ReportFHI.java
public static String[] getStartEndDateOfQuery() { SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-"); int months;//from w ww .j a va2 s. c om try { months = new Integer(rprops.getProperty("FHI.report.months.range")).intValue(); } catch (Exception e) { throw new RuntimeException("Cannot read/convert FHI.report.months.range:", e); } ; // from Calendar fromMonth = GregorianCalendar.getInstance(); fromMonth.add(Calendar.MONTH, -months); String fromYearMonth = dateformatter.format(fromMonth.getTime()); // to Calendar toMonth = GregorianCalendar.getInstance(); toMonth.add(Calendar.MONTH, -1); String toYearMonth = dateformatter.format(toMonth.getTime()); return new String[] { fromYearMonth + String.format("%02d", fromMonth.getActualMinimum(Calendar.DAY_OF_MONTH)), toYearMonth + toMonth.getActualMaximum(Calendar.DAY_OF_MONTH) }; }
From source file:org.openmrs.module.mdrtb.reporting.ReportUtil.java
public static Map<String, Date> getPeriodDates(Integer year, Integer quarter, Integer month) { // Validate input and construct start and end months int startMonth = 1; int endMonth = 12; // if the year is null, we don't have start and end dates, want to query from the beginning of time until today if (year == null && month == null && quarter == null) { Map<String, Date> periodDates = new HashMap<String, Date>(); ;// w ww . ja v a2 s.c om periodDates.put("startDate", null); periodDates.put("endDate", new Date()); return periodDates; } if (year == null || year < 1900 || year > 2100) { throw new IllegalArgumentException("Please enter a valid year"); } if (quarter != null) { if (quarter < 1 || quarter > 4) { throw new IllegalArgumentException("Please enter a valid quarter (1-4)"); } if (month != null) { throw new IllegalArgumentException("Please enter either a quarter or a month"); } endMonth = quarter * 3; startMonth = endMonth - 2; } if (month != null) { if (month < 1 || month > 12) { throw new IllegalArgumentException("Please enter a valid month (1-12)"); } startMonth = month; endMonth = month; } Map<String, Date> periodDates = new HashMap<String, Date>(); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, startMonth - 1); c.set(Calendar.DATE, 1); periodDates.put("startDate", c.getTime()); c.set(Calendar.MONTH, endMonth - 1); c.set(Calendar.DATE, c.getActualMaximum(Calendar.DATE)); periodDates.put("endDate", c.getTime()); return periodDates; }