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.huateng.ebank.framework.util.DateUtil.java
/** * ?// w w w.j a v a 2 s . c o m * */ public static List getEndWeekDate(Date startDate, Date endDate, SimpleDateFormat sdf) { Calendar cal = Calendar.getInstance(); int days = getDaysBetween(startDate, endDate); List list = new ArrayList<String>(); for (int i = 1; i < days; i++) { startDate = getNextDay(startDate); cal.setTime(startDate); // ????? int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// ? if (1 == dayWeek) { cal.add(Calendar.DAY_OF_MONTH, -1); } cal.setFirstDayOfWeek(Calendar.MONDAY);// int day = cal.get(Calendar.DAY_OF_WEEK);// ? cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);// ??? String imptimeBegin = sdf.format(cal.getTime()); cal.add(Calendar.DATE, 6); String imptimeEnd = sdf.format(cal.getTime()); list.add(imptimeEnd); } // ?? Set set = new HashSet(); List newList = new ArrayList(); for (Iterator iter = list.iterator(); iter.hasNext();) { Object element = iter.next(); if (set.add(element)) newList.add(element); } list.clear(); list.addAll(newList); return newList; }
From source file:net.sourceforge.fenixedu.presentationTier.TagLib.sop.examsMapNew.renderers.ExamsMapContentRenderer.java
@Override public StringBuilder renderDayLabel(ExamsMapSlot examsMapSlot, ExamsMap examsMap, String typeUser, PageContext pageContext) {/*w w w . j av a 2s . co m*/ this.examsMap = examsMap; StringBuilder strBuffer = new StringBuilder(); boolean isFirstDayOfSeason = ((examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH) == examsMap .getFirstDayOfSeason().get(Calendar.DAY_OF_MONTH)) && (examsMapSlot.getDay().get(Calendar.MONTH) == examsMap.getFirstDayOfSeason().get(Calendar.MONTH)) && (examsMapSlot.getDay().get(Calendar.YEAR) == examsMap.getFirstDayOfSeason().get(Calendar.YEAR))); boolean isSecondDayOfMonthAndFirstDayWasASunday = (examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH) == 2 && examsMapSlot.getDay().get(Calendar.DAY_OF_WEEK) == 2); if (examsMap.getInfoExecutionDegree() != null && typeUser.equals("sop")) { strBuffer.append("<a href='showExamsManagement.do?method=createByDay" + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + "&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + examsMap.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.CURRICULAR_YEAR_OID + "=" + examsMap.getCurricularYears().iterator().next() + "&" + PresentationConstants.DAY + "=" + examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH) + "&" + PresentationConstants.MONTH + "=" + (examsMapSlot.getDay().get(Calendar.MONTH) + 1) + "&" + PresentationConstants.YEAR + "=" + examsMapSlot.getDay().get(Calendar.YEAR) + "'>"); } strBuffer.append(examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH)); if ((examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH) == 1) || isFirstDayOfSeason || isSecondDayOfMonthAndFirstDayWasASunday) { strBuffer.append(" "); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.of")); strBuffer.append(" "); Locale locale = pageContext.getRequest().getLocale(); strBuffer.append(monthToString(examsMapSlot.getDay().get(Calendar.MONTH), locale)); } if (examsMapSlot.getDay().get(Calendar.DAY_OF_YEAR) == 1) { strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.comma")); strBuffer.append(examsMapSlot.getDay().get(Calendar.YEAR)); } if (examsMap.getInfoExecutionDegree() != null && typeUser.equals("sop")) { strBuffer.append("</a>"); } strBuffer.append("<br />"); return strBuffer; }
From source file:com.sammyun.util.DateUtil.java
/** * ?//from ww w. j a v a2s . c o m * * @param dateString String * @return int * @throws ParseException */ public static int getWeekDays(Date date) throws ParseException { Calendar calendar = DateUtils.toCalendar(date); int year = getYear(date); int month = getMonth(date); int maxDay = calendar.get(Calendar.DAY_OF_MONTH); int days = 0; // ?? if (isEqualYM(date)) { for (int day = 1; day < maxDay; day++) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date datestr = simpleDateFormat.parse(year + "-" + month + "-" + day); Calendar c = Calendar.getInstance(); c.setTime(datestr); if (c.get(Calendar.DAY_OF_WEEK) == 1 || c.get(Calendar.DAY_OF_WEEK) == 7) { days++; } } } else { for (int day = 1; day <= maxDay; day++) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date datestr = simpleDateFormat.parse(year + "-" + month + "-" + day); Calendar c = Calendar.getInstance(); c.setTime(datestr); if (c.get(Calendar.DAY_OF_WEEK) == 1 || c.get(Calendar.DAY_OF_WEEK) == 7) { days++; } } } return days; }
From source file:org.callistasoftware.netcare.core.api.impl.ScheduledActivityImpl.java
public static ScheduledActivity newFromEntity(ScheduledActivityEntity entity) { ScheduledActivityImpl scheduledActivity = new ScheduledActivityImpl(); scheduledActivity.healthPlanName = entity.getActivityDefinitionEntity().getHealthPlan().getName(); scheduledActivity.id = entity.getId(); scheduledActivity.activityDefinition = ActivityDefinitionImpl .newFromEntity(entity.getActivityDefinitionEntity()); Calendar cal = Calendar.getInstance(); cal.setTime(entity.getScheduledTime()); int day = cal.get(Calendar.DAY_OF_WEEK); scheduledActivity.day = new Option("weekday." + day, LocaleContextHolder.getLocale()); cal.setTime(new Date()); ApiUtil.dayBegin(cal);/*from w w w .j a v a 2 s. com*/ Date time = entity.getScheduledTime(); scheduledActivity.due = (time.compareTo(cal.getTime()) < 0); scheduledActivity.date = ApiUtil.formatDate(time); scheduledActivity.time = ApiUtil.formatTime(time); if (entity.getReportedTime() != null) { Calendar reportedCal = Calendar.getInstance(); reportedCal.setTime(entity.getReportedTime()); int repDay = reportedCal.get(Calendar.DAY_OF_WEEK); Date reportedTime = entity.getReportedTime(); scheduledActivity.reportedDay = new Option("weekday." + repDay, LocaleContextHolder.getLocale()); scheduledActivity.reportedDate = ApiUtil.formatDate(reportedTime); scheduledActivity.reportedTime = ApiUtil.formatTime(reportedTime); scheduledActivity.reported = new StringBuilder(scheduledActivity.reportedDate).append(" ") .append(scheduledActivity.reportedTime).toString(); final Calendar act = Calendar.getInstance(); act.setTime(entity.getActualTime()); int actWeekday = act.get(Calendar.DAY_OF_WEEK); scheduledActivity.actDay = new Option("weekday." + actWeekday, LocaleContextHolder.getLocale()); scheduledActivity.actDate = ApiUtil.formatDate(entity.getActualTime()); scheduledActivity.actTime = ApiUtil.formatTime(entity.getActualTime()); } if (entity.getActualTime() != null) { scheduledActivity.actualTime = ApiUtil.formatDate(entity.getActualTime()) + " " + ApiUtil.formatTime(entity.getActualTime()); } // Scheduled time within one week? final Date oneWeek = new DateTime(System.currentTimeMillis()).plusWeeks(1).toDate(); final Date scheduled = entity.getScheduledTime(); if (scheduled.before(oneWeek) && entity.getReportedTime() == null) { scheduledActivity.setReportingPossible(true); } else { scheduledActivity.setReportingPossible(false); } scheduledActivity.setExtra(entity.isExtra()); List<ActivityItemValuesEntity> activityEntities = entity.getActivities(); scheduledActivity.activityItemValues = new ActivityItemValues[activityEntities.size()]; for (int i = 0; i < scheduledActivity.activityItemValues.length; i++) { ActivityItemValuesEntity activityItemValuesEntity = activityEntities.get(i); if (activityItemValuesEntity instanceof MeasurementEntity) { scheduledActivity.activityItemValues[i] = MeasurementImpl .newFromEntity((MeasurementEntity) activityItemValuesEntity); } else if (activityItemValuesEntity instanceof EstimationEntity) { scheduledActivity.activityItemValues[i] = EstimationImpl .newFromEntity((EstimationEntity) activityItemValuesEntity); } else if (activityItemValuesEntity instanceof YesNoEntity) { scheduledActivity.activityItemValues[i] = YesNoImpl .newFromEntity((YesNoEntity) activityItemValuesEntity); } else if (activityItemValuesEntity instanceof TextEntity) { scheduledActivity.activityItemValues[i] = TextImpl .newFromEntity((TextEntity) activityItemValuesEntity); } } scheduledActivity.rejected = entity.isRejected(); scheduledActivity.patient = PatientBaseViewImpl .newFromEntity(entity.getActivityDefinitionEntity().getHealthPlan().getForPatient()); scheduledActivity.note = entity.getNote(); scheduledActivity.comments = new ActivityComment[entity.getComments().size()]; for (int i = 0; i < entity.getComments().size(); i++) { scheduledActivity.comments[i] = ActivityCommentImpl.newFromEntity(entity.getComments().get(i)); } return scheduledActivity; }
From source file:TimePeriod.java
/** * Setzt den von-Wert auf einen der Standard-Typen * //from w w w. ja v a 2s .co m * @param neuertyp */ public void setFromTyp(int neuertyp) { this.from_typ = neuertyp; if (from_typ != to_typ) typ = -1; else typ = neuertyp; switch (neuertyp) { case TODAY: from = new GregorianCalendar(); setMidnight(from); break; case YESTERDAY: from = new GregorianCalendar(); setMidnight(from); from.setTimeInMillis(from.getTimeInMillis() - ONE_DAY); break; case THIS_WEEK: from = new GregorianCalendar(); setMidnight(from); int day_of_week = from.get(Calendar.DAY_OF_WEEK); // unsere Woche beginnt am Montag. Montag hat den Wert 2 int day_offset_von; // wenn es sonntag ist, wird die zurck liegende woche betrachtet if (day_of_week == 1) { day_offset_von = -6; } else { day_offset_von = 2 - day_of_week; } // bis ist logischerweise 6-Tage nach von from.setTimeInMillis(from.getTimeInMillis() + ONE_DAY * day_offset_von); break; case LAST_WEEK: // wie diese woche, nur 7 tage weiter zurck from = new GregorianCalendar(); setMidnight(from); int day_of_week2 = from.get(Calendar.DAY_OF_WEEK); // unsere Woche beginnt am Montag. Montag hat den Wert 2 int day_offset_von2; // wenn es sonntag ist, wird die zurck liegende woche betrachtet if (day_of_week2 == 1) { day_offset_von2 = -13; } else { day_offset_von2 = -5 - day_of_week2; } from.setTimeInMillis(from.getTimeInMillis() + ONE_DAY * day_offset_von2); break; case THIS_MONTH: from = new GregorianCalendar(); setMidnight(from); from.set(Calendar.DAY_OF_MONTH, 1); break; case LAST_MONTH: from = new GregorianCalendar(); setMidnight(from); from.set(Calendar.DAY_OF_MONTH, 1); // der erste tag des letzten Monats ist vielleicht nicht mehr in // diesem Jahr, also // rckwrts laufen, bis wieder ein erster Tag gefunden wird from.setTimeInMillis(from.getTimeInMillis() - ONE_DAY); while (from.get(Calendar.DAY_OF_MONTH) != 1) from.setTimeInMillis(from.getTimeInMillis() - ONE_DAY); break; case THIS_JEAR: from = new GregorianCalendar(); setMidnight(from); from.set(Calendar.DAY_OF_MONTH, 1); from.set(Calendar.MONTH, 0); break; case LAST_JEAR: from = new GregorianCalendar(); int jahr = from.get(Calendar.YEAR); jahr--; setMidnight(from); from.set(Calendar.DAY_OF_MONTH, 1); from.set(Calendar.MONTH, 0); from.set(Calendar.YEAR, jahr); break; case EVER: from = new GregorianCalendar(); int jahr2 = from.get(Calendar.YEAR); setMidnight(from); from.set(2000, 0, 1, 0, 0, 0); break; } // Von darf nicht nach bis liegen, ist bis schon initialisiert, so muss // es angepasst werden if (to != null) if (to.before(from)) { to.setTimeInMillis(from.getTimeInMillis()); set2359(to); if (from_typ == TODAY) to_typ = TODAY; } }
From source file:com.aurel.track.fieldType.runtime.matchers.run.DateMatcherRT.java
/** * Reinitialize dayBegin and dayEnd//from w w w .j a va 2 s . c o m */ @Override public void setMatchValue(Object matcherValue) { super.setMatchValue(matcherValue); if (relation == MatchRelations.LATER_AS_LASTLOGIN && matcherContext != null) { matcherValue = matcherContext.getLastLoggedDate(); } Calendar calendaMatcherValue = new GregorianCalendar(matcherContext.getLocale()); calendaMatcherValue.setTime(new Date()); calendaMatcherValue = CalendarUtil.clearTime(calendaMatcherValue); int firstDayOfWeek = calendaMatcherValue.getFirstDayOfWeek(); switch (relation) { case MatchRelations.THIS_WEEK: calendaMatcherValue.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); dayBegin = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.WEEK_OF_YEAR, 1); calendaMatcherValue.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); dayEnd = calendaMatcherValue.getTime(); return; case MatchRelations.LAST_WEEK: calendaMatcherValue.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); dayEnd = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.WEEK_OF_YEAR, -1); calendaMatcherValue.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); dayBegin = calendaMatcherValue.getTime(); return; case MatchRelations.THIS_MONTH: calendaMatcherValue.set(Calendar.DAY_OF_MONTH, 1); dayBegin = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.MONTH, 1); calendaMatcherValue.set(Calendar.DAY_OF_MONTH, 1); dayEnd = calendaMatcherValue.getTime(); return; case MatchRelations.LAST_MONTH: calendaMatcherValue.set(Calendar.DAY_OF_MONTH, 1); dayEnd = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.MONTH, -1); calendaMatcherValue.set(Calendar.DAY_OF_MONTH, 1); dayBegin = calendaMatcherValue.getTime(); return; } if (matcherValue == null) { return; } //reinitialize dayBegin and dayEnd Date matcherValueDate = null; Integer matcherValueInteger = null; switch (relation) { case MatchRelations.MORE_THAN_DAYS_AGO: case MatchRelations.MORE_THAN_EQUAL_DAYS_AGO: case MatchRelations.LESS_THAN_DAYS_AGO: case MatchRelations.LESS_THAN_EQUAL_DAYS_AGO: try { matcherValueInteger = (Integer) matchValue; } catch (Exception e) { LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName() + " to Integer failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } calendaMatcherValue.setTime(new Date()); if (matcherValueInteger != null) { int matcherValueInt = matcherValueInteger.intValue(); if (relation == MatchRelations.MORE_THAN_EQUAL_DAYS_AGO) { matcherValueInt--; } if (relation == MatchRelations.LESS_THAN_EQUAL_DAYS_AGO) { matcherValueInt++; } calendaMatcherValue.add(Calendar.DATE, -matcherValueInt); } break; case MatchRelations.IN_MORE_THAN_DAYS: case MatchRelations.IN_MORE_THAN_EQUAL_DAYS: case MatchRelations.IN_LESS_THAN_DAYS: case MatchRelations.IN_LESS_THAN_EQUAL_DAYS: try { matcherValueInteger = (Integer) matchValue; } catch (Exception e) { LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName() + " to Integer failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } calendaMatcherValue.setTime(new Date()); if (matcherValueInteger != null) { int matcherValueInt = matcherValueInteger.intValue(); if (relation == MatchRelations.IN_MORE_THAN_EQUAL_DAYS) { matcherValueInt--; } if (relation == MatchRelations.IN_LESS_THAN_EQUAL_DAYS) { matcherValueInt++; } calendaMatcherValue.add(Calendar.DATE, matcherValueInt); } break; case MatchRelations.EQUAL_DATE: case MatchRelations.NOT_EQUAL_DATE: case MatchRelations.GREATHER_THAN_DATE: case MatchRelations.GREATHER_THAN_EQUAL_DATE: case MatchRelations.LESS_THAN_DATE: case MatchRelations.LESS_THAN_EQUAL_DATE: try { matcherValueDate = (Date) matchValue; } catch (Exception e) { LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName() + " to Date failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (matcherValueDate != null) { calendaMatcherValue.setTime(matcherValueDate); if (relation == MatchRelations.GREATHER_THAN_EQUAL_DATE) { calendaMatcherValue.add(Calendar.DATE, -1); } else { if (relation == MatchRelations.LESS_THAN_EQUAL_DATE) { calendaMatcherValue.add(Calendar.DATE, 1); } } } break; case MatchRelations.LATER_AS_LASTLOGIN: if (matcherContext != null) { dayBegin = matcherContext.getLastLoggedDate(); dayEnd = matcherContext.getLastLoggedDate(); } //return because later the dayBegin and dayEnd will be assigned again return; } calendaMatcherValue = CalendarUtil.clearTime(calendaMatcherValue); dayBegin = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.DATE, 1); dayEnd = calendaMatcherValue.getTime(); }
From source file:com.netflix.simianarmy.basic.BasicCalendar.java
/** {@inheritDoc} */ @Override//from www .j a v a2 s . c om public boolean isMonkeyTime(Monkey monkey) { if (cfg != null && cfg.getStrOrElse("simianarmy.calendar.isMonkeyTime", null) != null) { return cfg.getBool("simianarmy.calendar.isMonkeyTime"); } Calendar now = now(); int dow = now.get(Calendar.DAY_OF_WEEK); if (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) { return false; } int hour = now.get(Calendar.HOUR_OF_DAY); if (hour < openHour || hour > closeHour) { return false; } if (isHoliday(now)) { return false; } return true; }
From source file:jp.co.nemuzuka.utils.DateTimeUtils.java
/** * ??./*from ww w . java 2 s.co m*/ * ??????Date???? * ????????????????? * ??????????? * @param targetYyyyMM ? * @return index 0:??Date index 1:?Date */ public static List<Date> getStartEndDate4SunDay(String targetYyyyMM) { List<Date> list = getStartEndDate(targetYyyyMM); Date startDate = list.get(0); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(getTimeZone()); //?? while (true) { calendar.setTime(startDate); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { //????? break; } //1?? startDate = addDays(startDate, -1); } Date endDate = list.get(1); //? while (true) { calendar.setTime(endDate); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) { //????? break; } //1? endDate = addDays(endDate, 1); } List<Date> retList = new ArrayList<Date>(); retList.add(startDate); retList.add(endDate); return retList; }
From source file:KalendarDialog.java
private void setDayForDisplay(Calendar now) { int currentDay = now.get(Calendar.DATE); now.add(Calendar.DAY_OF_MONTH, -(now.get(Calendar.DATE) - 1)); // int startIndex = now.get(Calendar.DAY_OF_WEEK) - 1; // int year = now.get(Calendar.YEAR); // int month = now.get(Calendar.MONTH) + 1; // int lastDay = this.getLastDayOfMonth(year, month); // int endIndex = startIndex + lastDay - 1; // int startday = 1; for (int i = 0; i < 42; i++) { Color temp = days[i].getBackground(); if (temp.equals(display.getSystemColor(SWT.COLOR_BLUE))) { days[i].setBackground(display.getSystemColor(SWT.COLOR_WHITE)); }// w w w.j a va 2 s .c o m } for (int i = 0; i < 42; i++) { if (i >= startIndex && i <= endIndex) { days[i].setText("" + startday); if (startday == currentDay) { days[i].setBackground(display.getSystemColor(SWT.COLOR_BLUE)); // } startday++; } else { days[i].setText(""); } } }
From source file:com.li.bus.utils.DateUtils.java
/** * ? ?E/*from w ww . j av a 2 s . c om*/ */ public static int getWeek(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); if (c.get(Calendar.DAY_OF_WEEK) == 1) { return 7; } else { return c.get(Calendar.DAY_OF_WEEK) - 1; } }