List of usage examples for java.util Calendar setFirstDayOfWeek
public void setFirstDayOfWeek(int value)
SUNDAY
in the U.S., MONDAY
in France. From source file:br.com.transport.report.ManagerReportBean.java
/** * Retorna o primeiro dia da semana//from w w w. j a va 2s.c o m * @return */ private Calendar getInitCalendar() { Calendar init = GregorianCalendar.getInstance(); init.setFirstDayOfWeek(Calendar.SUNDAY); init.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); init.set(Calendar.HOUR_OF_DAY, 0); init.set(Calendar.MINUTE, 0); init.set(Calendar.SECOND, 0); init.setTime(init.getTime()); return init; }
From source file:org.cs.basic.test.util.DateUtils.java
/**? * @param date//from w ww . j av a 2 s. c om * @return */ public static int weekOfDay(Date date) { Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.MONDAY); //1 c.setMinimalDaysInFirstWeek(4); //?4??1 c.setTime(date); int weeknum = c.get(Calendar.WEEK_OF_YEAR); int vyear = c.get(Calendar.YEAR); int vmonth = c.get(Calendar.MONTH) + 1; //1????1 if (vmonth == 1 && weeknum > 6) { vyear--; } //????1 if (vmonth == 12 && weeknum == 1) { vyear++; } /*DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); System.out.println(format.format(date)+",weeknum:"+weeknum+",year:"+vyear);*/ return weeknum; }
From source file:com.panet.imeta.core.row.ValueDataUtil.java
public static Object weekOfYearISO8601(ValueMetaInterface metaA, Object dataA) throws KettleValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(Locale.ENGLISH); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(metaA.getDate(dataA)); return new Long(calendar.get(Calendar.WEEK_OF_YEAR)); }// w w w .j a v a 2 s .c o m throw new KettleValueException("The 'weekOfYearISO8601' function only works with dates"); }
From source file:org.openossad.util.core.row.ValueDataUtil.java
public static Object weekOfYearISO8601(ValueMetaInterface metaA, Object dataA) throws OpenDESIGNERValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(Locale.ENGLISH); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(metaA.getDate(dataA)); return new Long(calendar.get(Calendar.WEEK_OF_YEAR)); }/* w w w. j av a2 s . c o m*/ throw new OpenDESIGNERValueException("The 'weekOfYearISO8601' function only works with dates"); }
From source file:br.com.transport.report.ManagerReportBean.java
/** * Retorna lista com os dias da semana// ww w. j a v a 2 s .com * @return {@link List}< {@link Calendar} > */ private List<Calendar> createDayOfTheWeek() { Calendar firstDay = GregorianCalendar.getInstance(); firstDay.setFirstDayOfWeek(Calendar.SUNDAY); firstDay.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); firstDay.set(Calendar.HOUR_OF_DAY, 0); firstDay.set(Calendar.MINUTE, 0); firstDay.set(Calendar.SECOND, 0); List<Calendar> daysOfTheWeek = new LinkedList<Calendar>(); for (int count = 0; count < 7; count++) { Calendar temp = (Calendar) firstDay.clone(); temp.roll(Calendar.DAY_OF_WEEK, count); temp.setTime(temp.getTime()); daysOfTheWeek.add(temp); } return daysOfTheWeek; }
From source file:com.panet.imeta.core.row.ValueDataUtil.java
public static Object yearOfDateISO8601(ValueMetaInterface metaA, Object dataA) throws KettleValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(Locale.ENGLISH); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(metaA.getDate(dataA)); int week = calendar.get(Calendar.WEEK_OF_YEAR); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); // fix up for the year taking into account ISO8601 weeks if (week >= 52 && month == 0) year--;/* w w w . j a v a2s . com*/ if (week <= 2 && month == 11) year++; return new Long(year); } throw new KettleValueException("The 'yearOfDateISO8601' function only works with dates"); }
From source file:org.openossad.util.core.row.ValueDataUtil.java
public static Object yearOfDateISO8601(ValueMetaInterface metaA, Object dataA) throws OpenDESIGNERValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(Locale.ENGLISH); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(metaA.getDate(dataA)); int week = calendar.get(Calendar.WEEK_OF_YEAR); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); // fix up for the year taking into account ISO8601 weeks if (week >= 52 && month == 0) year--;//from w w w . j av a2 s . c o m if (week <= 2 && month == 11) year++; return new Long(year); } throw new OpenDESIGNERValueException("The 'yearOfDateISO8601' function only works with dates"); }
From source file:com.cognizant.trumobi.em.Email.java
public static String getWeekDays() { Calendar cal = Calendar.getInstance(); String string = Email.getPresentDay(); // Log.e("getPresentDay", ""+string); Date date = null;// ww w. j av a 2s . co m try { date = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH).parse(string); } catch (ParseException e) { e.printStackTrace(); } cal.setTime(date); SimpleDateFormat format = new SimpleDateFormat("MMM dd", Locale.US); Calendar firstCal = (Calendar) cal.clone(); firstCal.add(Calendar.DAY_OF_WEEK, firstCal.getFirstDayOfWeek() - firstCal.get(Calendar.DAY_OF_WEEK)); // SharedPreferences prefs = PreferenceManager // .getDefaultSharedPreferences(appContext); SharedPreferences prefs = new SharedPreferences(appContext); String WeekStartsOn = prefs.getString(appContext.getString(R.string.key_list_preference), ""); if (WeekStartsOn.equalsIgnoreCase("2")) { firstCal.setFirstDayOfWeek(Calendar.SATURDAY); } else if (WeekStartsOn.equalsIgnoreCase("3")) { firstCal.setFirstDayOfWeek(Calendar.SUNDAY); } else if (WeekStartsOn.equalsIgnoreCase("4")) { firstCal.setFirstDayOfWeek(Calendar.MONDAY); } int firstDayOfWeek = firstCal.getFirstDayOfWeek(); int dayOfWeek = firstCal.get(Calendar.DAY_OF_WEEK); if (firstDayOfWeek == 7) { firstCal.add(Calendar.DAY_OF_WEEK, -dayOfWeek); } else firstCal.add(Calendar.DAY_OF_WEEK, firstCal.getFirstDayOfWeek() - firstCal.get(Calendar.DAY_OF_WEEK)); String[] days = new String[2]; days[0] = format.format(firstCal.getTime()); Calendar lastCal = (Calendar) firstCal.clone(); lastCal.add(Calendar.DAY_OF_YEAR, 6); days[1] = format.format(lastCal.getTime()); String[] weekDays = Arrays.toString(days).split(","); // String weekVal2=weekDays[1].substring(weekDays[1].length()-1); String weekVal2 = weekDays[1].replace("]", ""); String weekVal = weekDays[0].substring(1) + " - " + weekVal2; return weekVal; }
From source file:com.hihframework.core.utils.DateUtils.java
/** * ??2004-07-28 ?//from w w w . j av a2 s.com * * @param date * @return ? */ public static String getDayWeek(java.sql.Date date) { String days[] = { "", "", "", "", "", "", "" }; Calendar cale = Calendar.getInstance(); cale.setTime(date); cale.setFirstDayOfWeek(Calendar.SUNDAY); return date.toString() + " " + days[cale.get(Calendar.DAY_OF_WEEK) - 1]; }
From source file:com.hihframework.core.utils.DateUtils.java
/** * ?/*from w ww . j a v a 2 s .c o m*/ * * @param date java.sql.Date ?? * @return Date[] java.sql.Date */ public static java.sql.Date[] getWeekDays(java.sql.Date date) { Calendar cale = Calendar.getInstance(); cale.setTime(date); cale.setFirstDayOfWeek(Calendar.SUNDAY); int days = 7; int today = cale.get(Calendar.DAY_OF_WEEK); long millis = cale.getTimeInMillis(); java.sql.Date dates[] = new java.sql.Date[days]; for (int i = 1; i <= days; i++) { long sub = (today - i) * 24 * 60 * 60 * 1000L; dates[i - 1] = new java.sql.Date(millis - sub); } cale = null; return dates; }