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:Main.java
public static boolean isCheckChangePermitted(Context context, Calendar date) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); String limitActivePref = sharedPrefs.getString("active-date-key", "ALLOW_ALL"); Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); Calendar yesterday;//from w w w .ja va 2s .c o m switch (limitActivePref) { case "ALLOW_CURRENT": return (date.compareTo(today) == 0); case "ALLOW_CURRENT_AND_NEXT_DAY": yesterday = (Calendar) today.clone(); yesterday.add(Calendar.DATE, -1); return (date.compareTo(yesterday) >= 0); case "ALLOW_CURRENT_AND_NEXT_DAY_AND_WEEKEND": yesterday = (Calendar) today.clone(); yesterday.add(Calendar.DATE, today.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY ? -2 : -1); return (date.compareTo(yesterday) >= 0); case "ALLOW_ALL": default: return true; } }
From source file:Main.java
public static Date startOfThisWeek() { Calendar cal = Calendar.getInstance(); int firstDay = cal.getFirstDayOfWeek(); cal.set(Calendar.DAY_OF_WEEK, firstDay); return startOfDay(cal.getTime()); }
From source file:Main.java
/** * Convert "YYYY-MM-DD" to "Friday X Month Year" * //from w w w . j a v a2 s. com * @param Date_In * @param conf * @return */ public static String dateNum2STR(String Date_In, Configuration conf) { String DayNo_STR = Date_In.substring(8, 10); int DayNo = Integer.parseInt(DayNo_STR); String MonthNo_STR = Date_In.substring(5, 7); int MonthNo = Integer.parseInt(MonthNo_STR); String Month_STR = formatMonth(Integer.parseInt(MonthNo_STR), conf.locale); String Year_STR = Date_In.substring(0, 4); int Year = Integer.parseInt(Year_STR); Calendar myCal = new GregorianCalendar(Year, MonthNo - 1, DayNo); int dayOfWeek = myCal.get(Calendar.DAY_OF_WEEK); // 6=Friday String dayOfWeek_STR = DateUtils.getDayOfWeekString(dayOfWeek, DateUtils.LENGTH_MEDIUM); return dayOfWeek_STR + " " + DayNo_STR + " " + Month_STR + " " + Year_STR; }
From source file:Main.java
/** * Get week by datetime, datetime format must be contracted with DATE_FORMAT. * * @param datetime/* w ww . ja v a 2 s . co m*/ * @return */ public static String getWeek(String datetime) { Calendar cal = Calendar.getInstance(); DateFormat f = new SimpleDateFormat(DATE_FORMAT); try { cal.setTime(f.parse(datetime)); int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1; if (week_index < 0) { week_index = 0; } return WEEKS[week_index]; } catch (ParseException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
/** * Get month day of week by year, month/*from w ww. j av a2 s .c o m*/ * * @param year * @param month * @return */ public static int getMonthDayOfWeek(int year, int month) { Calendar cal = Calendar.getInstance(); String dateString = year + "-" + (month > 9 ? month : ("0" + month)) + "-01"; String pattern = "yyyy-MM-dd"; Date date = null; try { SimpleDateFormat sdf = new SimpleDateFormat(pattern); date = sdf.parse(dateString); } catch (ParseException e) { } if (date != null) { cal.setTime(date); int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1; if (week_index < 0) { week_index = 0; } return week_index; } return -1; }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Integer getDayOfWeekNumber(Calendar cal) { return cal.get(Calendar.DAY_OF_WEEK); }
From source file:com.googlecode.commons.swing.util.DateUtils2.java
public static int getWeekNumber(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(d);//from ww w . ja va2 s . c om return cal.get(Calendar.DAY_OF_WEEK); }
From source file:Spring.Repaso02.ProductoDAO.java
public ArrayList<Producto> consultaAll(GregorianCalendar fecha) { int dia = (7 + fecha.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY) % 7; String selQuery = "select * from TProductos where Disponible = 0 or Disponible = ?"; List productos = jdbcTemplate.query(selQuery, new Object[] { dia }, new BeanPropertyRowMapper(Producto.class)); return (ArrayList) productos; }
From source file:net.kamhon.ieagle.util.DateUtil.java
public static Date getStartDateOfWeek(Date date) { Calendar calendarStartDate = DateUtil.setTime(date); Integer noOfDayOfWeek = calendarStartDate.get(Calendar.DAY_OF_WEEK) - 1; calendarStartDate.add(Calendar.DATE, -noOfDayOfWeek); return calendarStartDate.getTime(); }
From source file:TimeUtil.java
public static short mowFormat(long msecs) { synchronized (statFmtCal) { statFmtCal.setTime(new Date(msecs)); return ((short) ((statFmtCal.get(Calendar.DAY_OF_WEEK) - 1) * 1440 + statFmtCal.get(Calendar.HOUR_OF_DAY) * 60 + statFmtCal.get(Calendar.MINUTE))); }/* w w w . j a v a 2 s . c o m*/ }