Java Code Examples for java.util.Calendar#getActualMinimum()
The following examples show how to use
java.util.Calendar#getActualMinimum() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateUtils.java From common-project with Apache License 2.0 | 6 votes |
/** * 获取某年某月第一天 * @param year * @param month * @return */ public static String getFirstDayOfMonth(int year,int month){ Calendar cal = Calendar.getInstance(); //设置年份 cal.set(Calendar.YEAR,year); //设置月份 cal.set(Calendar.MONTH, month-1); //获取某月最小天数 int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH); //设置日历中月份的最小天数 cal.set(Calendar.DAY_OF_MONTH, firstDay); //格式化日期 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String firstDayOfMonth = sdf.format(cal.getTime()); return firstDayOfMonth; }
Example 2
Source File: DailySalesHeatMapFacadeREST.java From marathonv5 with Apache License 2.0 | 5 votes |
private HashMap<String, Long> runProductTypeQuery(Date date1, Integer productTypeId){ long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis(); Query baseQuery = em.createQuery(BASE_TYPE_QUERY); Calendar cal = Calendar.getInstance(); HashMap<String, Long> result = new HashMap<String, Long>(); { cal.setTime(date1); int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH); int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, dayMin); Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class); baseQuery.setParameter(p1, cal.getTime()); cal.set(Calendar.DAY_OF_MONTH, dayMax); Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class); baseQuery.setParameter(p2, cal.getTime()); Parameter<Integer> p3 = baseQuery.getParameter("productTypeId", Integer.class); baseQuery.setParameter(p3, productTypeId); List<Object[]> resultList = baseQuery.getResultList(); DIFF = (System.currentTimeMillis() - TIME); System.out.println(" Q TIME = "+DIFF+"ms"); for (int i=0; i < resultList.size(); i++){ Object o[] = resultList.get(i); result.put((String)o[1],(Long)o[0]); } } return result; }
Example 3
Source File: DateRangePrefixTree.java From lucene-solr with Apache License 2.0 | 5 votes |
private int slowSubCells(UnitNRShape lv) { int field = FIELD_BY_LEVEL[lv.getLevel()+1]; //short-circuit optimization (GregorianCalendar assumptions) if (field == -1 || field == Calendar.YEAR || field >= Calendar.HOUR_OF_DAY)//TODO make configurable return super.getNumSubCells(lv); Calendar cal = toCalendar(lv);//somewhat heavyweight op; ideally should be stored on UnitNRShape somehow return cal.getActualMaximum(field) - cal.getActualMinimum(field) + 1; }
Example 4
Source File: DateUtil.java From BaseUIFrame with MIT License | 5 votes |
/** * 获取某一周最后一天 * @return */ public static Date getLastDayByWeek(@NonNull Date date){ Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int min = calendar.getActualMinimum(Calendar.DAY_OF_WEEK); int current = calendar.get(Calendar.DAY_OF_WEEK); calendar.add(Calendar.DAY_OF_WEEK, min-current+6); return calendar.getTime(); }
Example 5
Source File: DateUtil.java From BaseUIFrame with MIT License | 5 votes |
/** * 获取某一周第一天 * @return */ public static Date getFirstDayByWeek(@NonNull Date date){ Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int min = calendar.getActualMinimum(Calendar.DAY_OF_WEEK); //获取周开始基准 int current = calendar.get(Calendar.DAY_OF_WEEK); //获取当天周内天数 calendar.add(Calendar.DAY_OF_WEEK, min-current); //当天-基准,获取周开始日期 return calendar.getTime(); }
Example 6
Source File: DateUtils.java From azeroth with Apache License 2.0 | 5 votes |
/** * 返回传入时间月份的第一天 * */ public static Date firstDayOfMonth(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int value = cal.getActualMinimum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, value); return cal.getTime(); }
Example 7
Source File: DisabledAlgorithmConstraints.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
DenyAfterConstraint(String algo, int year, int month, int day) { Calendar c; algorithm = algo; if (debug != null) { debug.println("DenyAfterConstraint read in as: year " + year + ", month = " + month + ", day = " + day); } c = new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("GMT")) .setDate(year, month - 1, day).build(); if (year > c.getActualMaximum(Calendar.YEAR) || year < c.getActualMinimum(Calendar.YEAR)) { throw new IllegalArgumentException( "Invalid year given in constraint: " + year); } if ((month - 1) > c.getActualMaximum(Calendar.MONTH) || (month - 1) < c.getActualMinimum(Calendar.MONTH)) { throw new IllegalArgumentException( "Invalid month given in constraint: " + month); } if (day > c.getActualMaximum(Calendar.DAY_OF_MONTH) || day < c.getActualMinimum(Calendar.DAY_OF_MONTH)) { throw new IllegalArgumentException( "Invalid Day of Month given in constraint: " + day); } denyAfterDate = c.getTime(); if (debug != null) { debug.println("DenyAfterConstraint date set to: " + dateFormat.format(denyAfterDate)); } }
Example 8
Source File: DateHelper.java From bird-java with MIT License | 5 votes |
/** * 返回传入时间月份的开始时间 * */ public static Date getMonthBegin(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int value = cal.getActualMinimum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, value); return getDayBegin(cal.getTime()); }
Example 9
Source File: ChartMeasurementView.java From openScale with GNU General Public License v3.0 | 5 votes |
private void setViewMode(final ViewMode mode) { viewMode = mode; Calendar viewModeCalender = Calendar.getInstance(); viewModeCalender.setTime(lastMeasurement.getDateTime()); switch (mode) { case DAY_OF_MONTH: minXValue = viewModeCalender.getMinimum(Calendar.DAY_OF_MONTH); maxXValue = viewModeCalender.getMaximum(Calendar.DAY_OF_MONTH); break; case WEEK_OF_MONTH: minXValue = 1; maxXValue = viewModeCalender.getActualMaximum(Calendar.WEEK_OF_MONTH); break; case WEEK_OF_YEAR: minXValue = viewModeCalender.getActualMinimum(Calendar.WEEK_OF_YEAR); maxXValue = viewModeCalender.getActualMaximum(Calendar.WEEK_OF_YEAR); break; case MONTH_OF_YEAR: minXValue = viewModeCalender.getActualMinimum(Calendar.MONTH); maxXValue = viewModeCalender.getActualMaximum(Calendar.MONTH); break; case DAY_OF_YEAR: minXValue = viewModeCalender.getActualMinimum(Calendar.DAY_OF_YEAR); maxXValue = viewModeCalender.getActualMaximum(Calendar.DAY_OF_YEAR); break; case DAY_OF_ALL: case WEEK_OF_ALL: case MONTH_OF_ALL: case YEAR_OF_ALL: minXValue = convertDateInShort(firstMeasurement.getDateTime()); maxXValue = convertDateInShort(lastMeasurement.getDateTime()); break; default: throw new IllegalArgumentException("view mode not implemented"); } setXValueFormat(mode); }
Example 10
Source File: DateUtils.java From apollo with GNU General Public License v2.0 | 5 votes |
/** * #func 获取当前时间当月的第一天<br> * * @author dongguoshuang */ public static Date getFirstDayOfMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH); return org.apache.commons.lang.time.DateUtils.setDays(date, firstDay); }
Example 11
Source File: DailySalesHeatMapFacadeREST.java From marathonv5 with Apache License 2.0 | 5 votes |
private HashMap<String, Long> runProductTypeQuery(Date date1, Integer productTypeId){ long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis(); Query baseQuery = em.createQuery(BASE_TYPE_QUERY); Calendar cal = Calendar.getInstance(); HashMap<String, Long> result = new HashMap<String, Long>(); { cal.setTime(date1); int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH); int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, dayMin); Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class); baseQuery.setParameter(p1, cal.getTime()); cal.set(Calendar.DAY_OF_MONTH, dayMax); Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class); baseQuery.setParameter(p2, cal.getTime()); Parameter<Integer> p3 = baseQuery.getParameter("productTypeId", Integer.class); baseQuery.setParameter(p3, productTypeId); List<Object[]> resultList = baseQuery.getResultList(); DIFF = (System.currentTimeMillis() - TIME); System.out.println(" Q TIME = "+DIFF+"ms"); for (int i=0; i < resultList.size(); i++){ Object o[] = resultList.get(i); result.put((String)o[1],(Long)o[0]); } } return result; }
Example 12
Source File: DailySalesHeatMapFacadeREST.java From marathonv5 with Apache License 2.0 | 5 votes |
private HashMap<String, Long> runBaseQuery(Date date){ Calendar cal = Calendar.getInstance(); long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis(); Query baseQuery = em.createQuery(BASE_QUERY); HashMap<String, Long> result = new HashMap<String, Long>(); { cal.setTime(date); int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH); int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, dayMin); Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class); baseQuery.setParameter(p1, cal.getTime()); cal.set(Calendar.DAY_OF_MONTH, dayMax); Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class); baseQuery.setParameter(p2, cal.getTime()); List<Object[]> resultList = baseQuery.getResultList(); DIFF = (System.currentTimeMillis() - TIME); System.out.println(" Q TIME = "+DIFF+"ms"); for (int i=0; i < resultList.size(); i++){ Object o[] = resultList.get(i); result.put((String)o[1],(Long)o[0]); } } return result; }
Example 13
Source File: DisabledAlgorithmConstraints.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
DenyAfterConstraint(String algo, int year, int month, int day) { Calendar c; algorithm = algo; if (debug != null) { debug.println("DenyAfterConstraint read in as: year " + year + ", month = " + month + ", day = " + day); } c = new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("GMT")) .setDate(year, month - 1, day).build(); if (year > c.getActualMaximum(Calendar.YEAR) || year < c.getActualMinimum(Calendar.YEAR)) { throw new IllegalArgumentException( "Invalid year given in constraint: " + year); } if ((month - 1) > c.getActualMaximum(Calendar.MONTH) || (month - 1) < c.getActualMinimum(Calendar.MONTH)) { throw new IllegalArgumentException( "Invalid month given in constraint: " + month); } if (day > c.getActualMaximum(Calendar.DAY_OF_MONTH) || day < c.getActualMinimum(Calendar.DAY_OF_MONTH)) { throw new IllegalArgumentException( "Invalid Day of Month given in constraint: " + day); } denyAfterDate = c.getTime(); if (debug != null) { debug.println("DenyAfterConstraint date set to: " + dateFormat.format(denyAfterDate)); } }
Example 14
Source File: DateUtil.java From JavaWeb with Apache License 2.0 | 5 votes |
public static String getFirstDayOfMonth(int year,int month){ Calendar cal = Calendar.getInstance(); //设置年份 cal.set(Calendar.YEAR,year); //设置月份 cal.set(Calendar.MONTH, month-1); //获取某月最大天数(即可以知道某月一共几天) int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH); //设置日历中月份的最大天数 cal.set(Calendar.DAY_OF_MONTH, lastDay); //格式化日期 SimpleDateFormat sdf = new SimpleDateFormat("dd"); return sdf.format(cal.getTime()); }
Example 15
Source File: DisabledAlgorithmConstraints.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
DenyAfterConstraint(String algo, int year, int month, int day) { Calendar c; algorithm = algo; if (debug != null) { debug.println("DenyAfterConstraint read in as: year " + year + ", month = " + month + ", day = " + day); } c = new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("GMT")) .setDate(year, month - 1, day).build(); if (year > c.getActualMaximum(Calendar.YEAR) || year < c.getActualMinimum(Calendar.YEAR)) { throw new IllegalArgumentException( "Invalid year given in constraint: " + year); } if ((month - 1) > c.getActualMaximum(Calendar.MONTH) || (month - 1) < c.getActualMinimum(Calendar.MONTH)) { throw new IllegalArgumentException( "Invalid month given in constraint: " + month); } if (day > c.getActualMaximum(Calendar.DAY_OF_MONTH) || day < c.getActualMinimum(Calendar.DAY_OF_MONTH)) { throw new IllegalArgumentException( "Invalid Day of Month given in constraint: " + day); } denyAfterDate = c.getTime(); if (debug != null) { debug.println("DenyAfterConstraint date set to: " + dateFormat.format(denyAfterDate)); } }
Example 16
Source File: DateConvertUtil.java From spring-boot-demo-all with Apache License 2.0 | 4 votes |
public static boolean isMonthStart(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.DATE) == calendar.getActualMinimum(Calendar.DAY_OF_MONTH); }
Example 17
Source File: Date.java From util with Apache License 2.0 | 4 votes |
/** * 得到当前所在自然月的第一天的开始,格式为长日期格式。例如:2012-03-01 00:00:00。 * @return Date */ public Date monthStart(){ Calendar c=Calendar.getInstance(); String startStr= toString("yyyy-M-")+c.getActualMinimum(Calendar.DATE)+" 00:00:00"; return Date.parseDate(startStr); }
Example 18
Source File: CalendarTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void TestActualMinMax() { Calendar cal = new GregorianCalendar(1967, MARCH, 10); cal.setFirstDayOfWeek(SUNDAY); cal.setMinimalDaysInFirstWeek(3); if (cal.getActualMinimum(DAY_OF_MONTH) != 1) { errln("Actual minimum date for 3/10/1967 should have been 1; got " + cal.getActualMinimum(DAY_OF_MONTH)); } if (cal.getActualMaximum(DAY_OF_MONTH) != 31) { errln("Actual maximum date for 3/10/1967 should have been 31; got " + cal.getActualMaximum(DAY_OF_MONTH)); } cal.set(MONTH, FEBRUARY); if (cal.getActualMaximum(DAY_OF_MONTH) != 28) { errln("Actual maximum date for 2/10/1967 should have been 28; got " + cal.getActualMaximum(DAY_OF_MONTH)); } if (cal.getActualMaximum(DAY_OF_YEAR) != 365) { errln("Number of days in 1967 should have been 365; got " + cal.getActualMaximum(DAY_OF_YEAR)); } cal.set(YEAR, 1968); if (cal.getActualMaximum(DAY_OF_MONTH) != 29) { errln("Actual maximum date for 2/10/1968 should have been 29; got " + cal.getActualMaximum(DAY_OF_MONTH)); } if (cal.getActualMaximum(DAY_OF_YEAR) != 366) { errln("Number of days in 1968 should have been 366; got " + cal.getActualMaximum(DAY_OF_YEAR)); } // Using week settings of SUNDAY/3 (see above) if (cal.getActualMaximum(WEEK_OF_YEAR) != 52) { errln("Number of weeks in 1968 should have been 52; got " + cal.getActualMaximum(WEEK_OF_YEAR)); } cal.set(YEAR, 1976); // Using week settings of SUNDAY/3 (see above) if (cal.getActualMaximum(WEEK_OF_YEAR) != 53) { errln("Number of weeks in 1976 should have been 53; got " + cal.getActualMaximum(WEEK_OF_YEAR)); } }
Example 19
Source File: CalendarHeader.java From microba with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void reflectData() { Calendar cal = Calendar.getInstance(zone, locale); cal.setTime(date == null ? new Date() : date); SimpleDateFormat fmt = new SimpleDateFormat("E", locale); fmt.setTimeZone(zone); int numDaysInWeek = cal.getActualMaximum(Calendar.DAY_OF_WEEK) - cal.getActualMinimum(Calendar.DAY_OF_WEEK) + 1; int firstDayOfWeek = cal.getFirstDayOfWeek(); cal.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); removeAll(); setLayout(new GridLayout(1, numDaysInWeek, 2, 2)); setBackground(isEnabled() ? backgroundColorActive : backgroundColorInactive); for (int i = 0; i < numDaysInWeek; i++) { JLabel label = new JLabel(); // TODO: add option to control limit length: label.setText(fmt.format(cal.getTime())/* .substring(0,1) */); label.setForeground(isEnabled() ? foregroundColorActive : foregroundColorInactive); label.setHorizontalAlignment(SwingConstants.CENTER); label.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0)); Font boldFont = label.getFont().deriveFont(Font.BOLD); label.setFont(boldFont); add(label); boolean isHolliday = false; if (holidayPolicy != null) { isHolliday = holidayPolicy.isWeekend(this, cal); } if (isHolliday) label.setForeground(isEnabled() ? foregroundColorWeekendEnabled : foregroundColorWeekendDisabled); cal.add(Calendar.DAY_OF_WEEK, 1); } setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 1)); revalidate(); repaint(); }
Example 20
Source File: DateConvertUtil.java From spring-boot-demo-all with Apache License 2.0 | 4 votes |
public static boolean isMonthStart(String date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(StringToDate(date, "yyyy-MM-dd")); return calendar.get(Calendar.DATE) == calendar.getActualMinimum(Calendar.DAY_OF_MONTH); }