List of usage examples for java.util Calendar DAY_OF_WEEK
int DAY_OF_WEEK
To view the source code for java.util Calendar DAY_OF_WEEK.
Click Source Link
get
and set
indicating the day of the week. From source file:com.baifendian.swordfish.execserver.parameter.placeholder.TimePlaceholderUtil.java
/** * ? <p>/*from w ww . ja v a 2 s .c o m*/ */ public static Date getSunday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); // ? cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); return cal.getTime(); }
From source file:com.application.utils.FastDateParser.java
private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) { DateFormatSymbols dfs = new DateFormatSymbols(locale); switch (field) { case Calendar.AM_PM: return dfs.getAmPmStrings(); case Calendar.DAY_OF_WEEK: return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays(); case Calendar.ERA: return dfs.getEras(); case Calendar.MONTH: return isLong ? dfs.getMonths() : dfs.getShortMonths(); }/* w ww . j ava2 s . c o m*/ return null; }
From source file:egovframework.oe1.cms.cmm.web.EgovOe1SchdulManageController.java
/** * ? //from ww w .jav a2s.c om * @param searchVO * @param commandMap * @param deptSchdulManageVO * @param model * @return "/cms/cmm/EgovSchdulManageWeekList" * @throws Exception */ @RequestMapping(value = "/cms/cmm/EgovOe1SchdulManageWeekList.do") public String EgovDeptSchdulManageWeekList(@ModelAttribute("searchVO") EgovOe1ComDefaultVO searchVO, Map commandMap, EgovOe1SchdulManageVO deptSchdulManageVO, ModelMap model) throws Exception { //Spring Security Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? model.addAttribute("searchKeyword", commandMap.get("searchKeyword") == null ? "" : (String) commandMap.get("searchKeyword")); model.addAttribute("searchCondition", commandMap.get("searchCondition") == null ? "" : (String) commandMap.get("searchCondition")); // ? EgovOe1ComDefaultCodeVO vo = new EgovOe1ComDefaultCodeVO(); vo.setCodeId("OE1028"); List schdulSeCode_result = cmmUseService.selectCmmCodeDetail(vo); model.addAttribute("schdulSeCode_result", schdulSeCode_result); // ? vo = new EgovOe1ComDefaultCodeVO(); vo.setCodeId("OE1008"); List year_result = cmmUseService.selectCmmCodeDetail(vo); model.addAttribute("year_result", year_result); // vo = new EgovOe1ComDefaultCodeVO(); vo.setCodeId("OE1013"); List month_result = cmmUseService.selectCmmCodeDetail(vo); model.addAttribute("month_result", month_result); /* ***************************************************************** // ? ? ****************************************************************** */ Calendar calNow = Calendar.getInstance(); Calendar calBefore = Calendar.getInstance(); Calendar calNext = Calendar.getInstance(); String strYear = deptSchdulManageVO.getSearchYear(); String strMonth = deptSchdulManageVO.getSearchMonth(); String strWeek = deptSchdulManageVO.getSearchWeek(); String strSchdulSeCode = deptSchdulManageVO.getSearchSchdulSeCode(); int iNowYear = 0; int iNowMonth = 0; int iNowDate = 0; int iNowWeek = 0; if ((strYear != null && !"".equals(strYear)) && (strMonth != null && !"".equals(strMonth)) && (strWeek != null && !"".equals(strWeek))) { iNowYear = Integer.parseInt(strYear); iNowMonth = Integer.parseInt(strMonth); iNowWeek = Integer.parseInt(strWeek); } else { iNowYear = calNow.get(Calendar.YEAR); iNowMonth = (calNow.get(Calendar.MONTH) + 1); iNowDate = calNow.get(Calendar.DATE); } //System.out.println("strYear=====>" + strYear); //System.out.println("strMonth=====>" + strMonth); //System.out.println("strWeek=====>" + strWeek); //System.out.println("iNowYear=====>" + iNowYear); //System.out.println("iNowMonth=====>"+ iNowMonth); //System.out.println("iNowDate=====>" + iNowDate); //System.out.println("Calendar.WEEK_OF_MONTH==>"+Calendar.WEEK_OF_MONTH); //?/ calNow.set(iNowYear, iNowMonth - 1, 1); calBefore.set(iNowYear, iNowMonth - 1, 1); calNext.set(iNowYear, iNowMonth - 1, 1); calBefore.add(Calendar.MONTH, -1); calNext.add(Calendar.MONTH, +1); int startDay = calNow.getMinimum(Calendar.DATE); int endDay = calNow.getActualMaximum(Calendar.DAY_OF_MONTH); int startWeek = calNow.get(Calendar.DAY_OF_WEEK); //System.out.println(" ?===>"+startWeek); ArrayList listWeekGrop = new ArrayList(); ArrayList listWeekDate = new ArrayList(); String sUseDate = ""; calBefore.add(Calendar.DATE, calBefore.getActualMaximum(Calendar.DAY_OF_MONTH) - (startWeek - 1)); for (int i = 1; i < startWeek; i++) { sUseDate = Integer.toString(calBefore.get(Calendar.YEAR)); sUseDate += DateTypeIntForString(calBefore.get(Calendar.MONTH) + 1); sUseDate += DateTypeIntForString(calBefore.get(Calendar.DATE)); listWeekDate.add(sUseDate); calBefore.add(Calendar.DATE, +1); } int iBetweenCount = startWeek; // ?. BETWEEN for (int i = 1; i <= endDay; i++) { sUseDate = Integer.toString(iNowYear); sUseDate += Integer.toString(iNowMonth).length() == 1 ? "0" + Integer.toString(iNowMonth) : Integer.toString(iNowMonth); sUseDate += Integer.toString(i).length() == 1 ? "0" + Integer.toString(i) : Integer.toString(i); listWeekDate.add(sUseDate); if (iBetweenCount % 7 == 0) { listWeekGrop.add(listWeekDate); listWeekDate = new ArrayList(); if ((strYear == null || "".equals(strYear)) && i < iNowDate) { iNowWeek++; } } // 7? ?? if (i == endDay) { for (int j = listWeekDate.size(); j < 7; j++) { String sUseNextDate = Integer.toString(calNext.get(Calendar.YEAR)); sUseNextDate += DateTypeIntForString(calNext.get(Calendar.MONTH) + 1); sUseNextDate += DateTypeIntForString(calNext.get(Calendar.DATE)); listWeekDate.add(sUseNextDate); calNext.add(Calendar.DATE, +1); } listWeekGrop.add(listWeekDate); } iBetweenCount++; } model.addAttribute("year", iNowYear + ""); model.addAttribute("month", ((iNowMonth) + "").length() == 1 ? "0" + (iNowMonth) : (iNowMonth)); model.addAttribute("week", iNowWeek + ""); model.addAttribute("dayOfMonth", (Calendar.WEEK_OF_MONTH) + ""); model.addAttribute("listWeekGrop", listWeekGrop); List listWeek = (List) listWeekGrop.get(iNowWeek); commandMap.put("searchMode", "WEEK"); commandMap.put("schdulBgnde", (String) listWeek.get(0)); commandMap.put("schdulEndde", (String) listWeek.get(listWeek.size() - 1)); commandMap.put("searchSchdulSeCode", strSchdulSeCode); String sNowMonth = ""; if (((iNowMonth) + "").length() == 1) { sNowMonth = "0" + (iNowMonth); } else { sNowMonth = (iNowMonth) + ""; } deptSchdulManageVO.setSearchYear(iNowYear + ""); deptSchdulManageVO.setSearchMonth(sNowMonth); deptSchdulManageVO.setSearchWeek(iNowWeek + ""); //? ? ??. model.addAttribute("searchMode", deptSchdulManageVO); List resultList = egovDeptSchdulManageService.selectDeptSchdulManageRetrieve(commandMap); model.addAttribute("resultList", resultList); return "/cms/cmm/EgovSchdulManageWeekList"; }
From source file:com.sunchenbin.store.feilong.core.date.DateUtil.java
/** * <code>week</code>./*from ww w . j a v a2 s . c o m*/ * * <pre> * 2015-7-29 14:08 * * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY) * return 2015-01-02 00:00:00.000 * * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY) * return 2015-01-05 00:00:00.000 * </pre> * * @param date * * @param week * 1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY}, * {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY} * @return the first week of specify date year * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY * @since 1.3.0 */ public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) { Calendar calendar = toCalendar(date); calendar.clear(); calendar.set(Calendar.YEAR, getYear(date)); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1); calendar.set(Calendar.DAY_OF_WEEK, week); //DAY_OF_WEEK_IN_MONTH ? DAY_OF_WEEK ,??? // WEEK_OF_MONTH WEEK_OF_YEAR ??,? ? getFirstDayOfWeek() getMinimalDaysInFirstWeek() //DAY_OF_MONTH 1 7 DAY_OF_WEEK_IN_MONTH 1 //8 14 DAY_OF_WEEK_IN_MONTH 2,? //DAY_OF_WEEK_IN_MONTH 0 DAY_OF_WEEK_IN_MONTH 1 ? //?,,? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1 //?,???? //, 31 , DAY_OF_WEEK_IN_MONTH -1 DAY_OF_WEEK_IN_MONTH 5 DAY_OF_WEEK_IN_MONTH 4 ?? return CalendarUtil.toDate(calendar); }
From source file:com.twitter.hraven.datasource.AppSummaryService.java
/** * find out the top of the day/week timestamp * @param runId// w w w .j a v a 2 s. c o m * @return top of the day/week timestamp */ long getTimestamp(long runId, AggregationConstants.AGGREGATION_TYPE aggType) { if (AggregationConstants.AGGREGATION_TYPE.DAILY.equals(aggType)) { // get top of the hour long dayTimestamp = runId - (runId % Constants.MILLIS_ONE_DAY); return dayTimestamp; } else if (AggregationConstants.AGGREGATION_TYPE.WEEKLY.equals(aggType)) { // get top of the hour Calendar c = Calendar.getInstance(); c.setTimeInMillis(runId); int d = c.get(Calendar.DAY_OF_WEEK); // get the first day of the week long weekTimestamp = runId - (d - 1) * Constants.MILLIS_ONE_DAY; // get the top of the day for that first day weekTimestamp = weekTimestamp - weekTimestamp % Constants.MILLIS_ONE_DAY; return weekTimestamp; } return 0L; }
From source file:Holidays.java
public static java.util.Calendar LaborDayObserved(int nYear) { // The first Monday in September int nX;//from ww w .j a v a 2s . co m int nMonth = 8; // September java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(nYear, 9, 1); nX = cal.get(Calendar.DAY_OF_WEEK); switch (nX) { case 0: // Sunday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 2); return cal; case 1: // Monday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 7); return cal; case 2: // Tuesday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 6); return cal; case 3: // Wednesday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 5); return cal; case 4: // Thrusday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 4); return cal; case 5: // Friday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 3); return cal; default: // Saturday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 2); return cal; } }
From source file:org.eevolution.form.CRP.java
/** * Create Category Dataset based on Weight , date start and resource * @param start/*from ww w .j a va2 s . c o m*/ * @param resource * @return CategoryDataset */ protected CategoryDataset createWeightDataset(Timestamp start, MResource rosource) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND); gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = MResourceType.get(Env.getCtx(), rosource.getS_ResourceType_ID()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "SELECT SUM( (mo.qtyordered-mo.qtydelivered)*(SELECT mp.weight FROM M_Product mp WHERE mo.m_product_id=mp.m_product_id )) FROM PP_Order mo WHERE AD_Client_ID=?", rosource.getAD_Client_ID()); double dailyCapacity = rosource.getDailyCapacity().doubleValue(); double utilization = rosource.getPercentUtilization().doubleValue(); double summary = 0; int day = 0; while (day < 32) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:org.hawkular.alerts.api.model.action.TimeConstraint.java
private boolean checkRelative(long timestamp) throws IllegalArgumentException { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timestamp);/*from w w w .jav a 2 s.co m*/ if (inRange) { // Check month int month = cal.get(Calendar.MONTH); if (startMonth != -1 && endMonth != -1 && !isInInterval(startMonth, endMonth, month)) { return false; } // Check day int day = cal.get(Calendar.DAY_OF_WEEK); if (startDay != -1 && endDay != -1 && !isInInterval(startDay, endDay, day)) { return false; } // Check minute int minute = (cal.get(Calendar.HOUR_OF_DAY) * 60) + cal.get(Calendar.MINUTE); if (startMinute != -1 && endMinute != -1 && !isInInterval(startMinute, endMinute, minute)) { return false; } return true; } else { // Check month int month = cal.get(Calendar.MONTH); if (startMonth != -1 && endMonth != -1 && !isInInterval(startMonth, endMonth, month)) { return true; } // Check day int day = cal.get(Calendar.DAY_OF_WEEK); if (startDay != -1 && endDay != -1 && !isInInterval(startDay, endDay, day)) { return true; } // Check minute int minute = (cal.get(Calendar.HOUR_OF_DAY) * 60) + cal.get(Calendar.MINUTE); if (startMinute != -1 && endMinute != -1 && !isInInterval(startMinute, endMinute, minute)) { return true; } return false; } }
From source file:fr.paris.lutece.plugins.calendar.service.Utils.java
/** * Checks if the day if Off (ie: Sunday) or not * @param calendar A calendar object positionned on the day to check * @return True if the day if Off, otherwise false *///from w ww .ja v a2 s. com public static boolean isDayOff(Calendar calendar) { int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if ((nDayOfWeek == Calendar.SATURDAY) || (nDayOfWeek == Calendar.SUNDAY)) { return true; } // Add other checks here return false; }
From source file:com.mirth.connect.plugins.datapruner.DataPrunerService.java
private Trigger createTrigger(Properties properties) throws ParseException { String interval = PropertyLoader.getProperty(properties, "interval"); if (interval.equals("disabled")) { return null; }//from w w w . j av a 2s. c o m ScheduleBuilder<?> schedule = null; if (interval.equals("hourly")) { schedule = cronSchedule("0 0 * * * ?"); } else { SimpleDateFormat timeDateFormat = new SimpleDateFormat("hh:mm aa"); DateFormatter timeFormatter = new DateFormatter(timeDateFormat); String time = PropertyLoader.getProperty(properties, "time"); Date timeDate = (Date) timeFormatter.stringToValue(time); Calendar timeCalendar = Calendar.getInstance(); timeCalendar.setTime(timeDate); if (interval.equals("daily")) { schedule = dailyAtHourAndMinute(timeCalendar.get(Calendar.HOUR_OF_DAY), timeCalendar.get(Calendar.MINUTE)); } else if (interval.equals("weekly")) { SimpleDateFormat dayDateFormat = new SimpleDateFormat("EEEEEEEE"); DateFormatter dayFormatter = new DateFormatter(dayDateFormat); String dayOfWeek = PropertyLoader.getProperty(properties, "dayOfWeek"); Date dayDate = (Date) dayFormatter.stringToValue(dayOfWeek); Calendar dayCalendar = Calendar.getInstance(); dayCalendar.setTime(dayDate); schedule = weeklyOnDayAndHourAndMinute(dayCalendar.get(Calendar.DAY_OF_WEEK), timeCalendar.get(Calendar.HOUR_OF_DAY), timeCalendar.get(Calendar.MINUTE)); } else if (interval.equals("monthly")) { SimpleDateFormat dayDateFormat = new SimpleDateFormat("DD"); DateFormatter dayFormatter = new DateFormatter(dayDateFormat); String dayOfMonth = PropertyLoader.getProperty(properties, "dayOfMonth"); Date dayDate = (Date) dayFormatter.stringToValue(dayOfMonth); Calendar dayCalendar = Calendar.getInstance(); dayCalendar.setTime(dayDate); schedule = monthlyOnDayAndHourAndMinute(dayCalendar.get(Calendar.DAY_OF_MONTH), timeCalendar.get(Calendar.HOUR_OF_DAY), timeCalendar.get(Calendar.MINUTE)); } else { logger.error("Invalid pruner interval: " + interval); return null; } } return newTrigger()// @formatter:off .withIdentity(PRUNER_TRIGGER_KEY).withSchedule(schedule).startNow().build(); // @formatter:on }