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:de.austinpadernale.holidays.Holiday.java
public Calendar shift(Calendar cal, String country, String region) { int dow = cal.get(Calendar.DAY_OF_WEEK); if (dow != Calendar.SATURDAY && dow != Calendar.SUNDAY) { return cal; }/* w w w .j a va2s .c om*/ HolidayShift hs = getShift(country, region); if (hs == null || hs.getShiftType() == ShiftType.None) { return cal; } int step; switch (hs.getShiftType()) { case Back: step = -1; break; case Forth: step = 1; break; case BackAndForth: step = dow == Calendar.SATURDAY ? -1 : 1; break; default: return cal; } while (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) { cal.add(Calendar.DATE, step); dow = cal.get(Calendar.DAY_OF_WEEK); } return cal; }
From source file:com.projity.contrib.calendar.JXXMonthView.java
/** * Resets the UI property to a value from the current look and feel. *//*from w ww. j a v a 2s . co m*/ public void updateUI() { super.updateUI(); String[] daysOfTheWeek = (String[]) UIManager.get("JXMonthView.daysOfTheWeek"); // Use some meaningful default if the UIManager doesn't have anything // for us. // PROJITY_MODIFICATION int w0 = 0; int w1 = 1; if (isChinese()) { w0 = 2; w1 = 3; } if (daysOfTheWeek == null) { daysOfTheWeek = new String[DAYS_IN_WEEK]; Calendar weekCal = calendarInstance(); SimpleDateFormat format = dateFormatInstance("E"); for (int i = 0; i < DAYS_IN_WEEK; i++) { weekCal.set(Calendar.DAY_OF_WEEK, i + 1); daysOfTheWeek[i] = format.format(weekCal.getTime()).substring(w0, w1).toUpperCase(); } // daysOfTheWeek = new String[] { "S", "M", "T", "W", "T", "F", "S" }; } setDaysOfTheWeek(daysOfTheWeek); Color color = UIManager.getColor("JXMonthView.monthStringBackground"); // Use some meaningful default if the UIManager doesn't have anything // for us. if (color == null) { color = Color.WHITE;//PROJITY_MODIFICATION } setMonthStringBackground(color); color = UIManager.getColor("JXMonthView.selectedBackground"); // Use some meaningful default if the UIManager doesn't have anything // for us. if (color == null) { color = Color.LIGHT_GRAY; } setSelectedBackground(color); }
From source file:Holidays.java
public static java.util.Calendar IndependenceDayObserved(int nYear) { int nX;// www.j av a 2 s. co m int nMonth = 6; // July java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 4); nX = cal.get(Calendar.DAY_OF_WEEK); switch (nX) { case 0: // Sunday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 5); return cal; case 1: // Monday case 2: // Tuesday case 3: // Wednesday case 4: // Thrusday case 5: // Friday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 4); return cal; default: // Saturday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 3); return cal; } }
From source file:com.baifendian.swordfish.execserver.parameter.placeholder.TimePlaceholderUtil.java
/** * ? <p>//from w ww .jav a2 s. c o m */ public static Date getMonday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); // ? cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return cal.getTime(); }
From source file:ch.algotrader.service.CalendarServiceImpl.java
/** * gets the weekday of the specified date * @param timeZone// w w w . j a v a 2 s .c om */ private WeekDay getWeekDay(final Date date, final TimeZone timeZone) { Calendar cal = new GregorianCalendar(); cal.setTimeZone(timeZone); cal.setTime(date); return WeekDay.fromValue(cal.get(Calendar.DAY_OF_WEEK)); }
From source file:com.easysoft.build.manager.BuildConfigInfoService.java
private static String makeWeekBugDeployPackName(RepInfo ri) throws Exception { Date curDate = DateUtil.toDate(ri.getCreateDate(), "yyyyMMdd");// ? String dateVersion = (ri.getVersionPattern() == null ? "" : new SimpleDateFormat(ri.getVersionPattern()).format(curDate));// ?? // ????//w w w. java 2 s. c om Calendar cal = Calendar.getInstance(); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // ??02-08 String smallVersion = (dayOfWeek == Calendar.SUNDAY) ? "08" // 1 : new DecimalFormat("00").format(dayOfWeek);// 2-7 String patchName = ri.getBand() + "." + ri.getVersionNo() + ri.getSpNo() + "." + dateVersion + smallVersion + "." + ri.getVersionSuffix(); return patchName; }
From source file:models.Schedule.java
private boolean areAllSetRangesUnitsEqual(final Calendar lastRunCalendar, final Calendar calendar, final List<Integer> nonDefaultUnits) { boolean eq = true; for (int unitType : nonDefaultUnits) { switch (unitType) { case Calendar.MINUTE: eq = (lastRunCalendar.get(Calendar.MINUTE) == calendar.get(Calendar.MINUTE) && lastRunCalendar.get(Calendar.HOUR_OF_DAY) == calendar.get(Calendar.HOUR_OF_DAY) && lastRunCalendar.get(Calendar.DAY_OF_YEAR) == calendar.get(Calendar.DAY_OF_YEAR) && lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)); break; case Calendar.HOUR_OF_DAY: eq = (lastRunCalendar.get(Calendar.HOUR_OF_DAY) == calendar.get(Calendar.HOUR_OF_DAY) && lastRunCalendar.get(Calendar.DAY_OF_YEAR) == calendar.get(Calendar.DAY_OF_YEAR) && lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)); break; case Calendar.DAY_OF_MONTH: eq = (lastRunCalendar.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH) && lastRunCalendar.get(Calendar.DAY_OF_YEAR) == calendar.get(Calendar.DAY_OF_YEAR) && lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)); break; case Calendar.DAY_OF_WEEK: eq = (lastRunCalendar.get(Calendar.DAY_OF_WEEK) == calendar.get(Calendar.DAY_OF_WEEK) && lastRunCalendar.get(Calendar.DAY_OF_YEAR) == calendar.get(Calendar.DAY_OF_YEAR) && lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)); break; case Calendar.YEAR: eq = lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR); break; }//from w ww .ja va 2s . c om if (!eq) { // any one unit check is different, so not all equal return eq; } } return eq; // they were _all_ equal }
From source file:com.rockagen.commons.util.CommUtil.java
/** * Return the current day of week/*w ww.j a v a2 s .c o m*/ * * @param date Date * @return current day of week */ public static int getCurrentDayOfWeek(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.get(Calendar.DAY_OF_WEEK); }
From source file:com.panet.imeta.job.entries.special.JobEntrySpecial.java
private long getNextWeeklyExecutionTime() { Calendar calendar = Calendar.getInstance(); long nowMillis = calendar.getTimeInMillis(); int amHour = hour; if (amHour > 12) { amHour = amHour - 12;/*ww w . j av a2s.c om*/ calendar.set(Calendar.AM_PM, Calendar.PM); } else { calendar.set(Calendar.AM_PM, Calendar.AM); } calendar.set(Calendar.HOUR, amHour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.DAY_OF_WEEK, weekDay + 1); if (calendar.getTimeInMillis() <= nowMillis) { calendar.add(Calendar.WEEK_OF_YEAR, 1); } return calendar.getTimeInMillis() - nowMillis; }
From source file:com.layer.atlas.Atlas.java
/** Today, Yesterday, Weekday or Weekday + date */ public static String formatTimeDay(Date sentAt) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);//from ww w . ja va2 s . c o m cal.set(Calendar.SECOND, 0); long todayMidnight = cal.getTimeInMillis(); long yesterMidnight = todayMidnight - Tools.TIME_HOURS_24; long weekAgoMidnight = todayMidnight - Tools.TIME_HOURS_24 * 7; String timeBarDayText = null; if (sentAt.getTime() > todayMidnight) { timeBarDayText = "Today"; } else if (sentAt.getTime() > yesterMidnight) { timeBarDayText = "Yesterday"; } else if (sentAt.getTime() > weekAgoMidnight) { cal.setTime(sentAt); timeBarDayText = Tools.TIME_WEEKDAYS_NAMES[cal.get(Calendar.DAY_OF_WEEK) - 1]; } else { timeBarDayText = Tools.sdfDayOfWeek.format(sentAt); } return timeBarDayText; }