List of usage examples for java.util Calendar WEEK_OF_YEAR
int WEEK_OF_YEAR
To view the source code for java.util Calendar WEEK_OF_YEAR.
Click Source Link
get
and set
indicating the week number within the current year. From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ?/*ww w .j a v a2 s. co m*/ * * @param date * @return */ public static Date getWeekEnd(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.get(Calendar.WEEK_OF_YEAR); int firstDay = calendar.getFirstDayOfWeek(); calendar.set(Calendar.DAY_OF_WEEK, 8 - firstDay); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }
From source file:org.cs.basic.test.util.DateUtils.java
/**? * @param date/* w w w . j a v a 2 s . c o m*/ * @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.discovery.darchrow.date.DateUtil.java
/** * ?{@link Calendar#WEEK_OF_YEAR}, 1,52(365/7=52.14). * /*from ww w .j a v a 2s . c o m*/ * <p> * ?:<br> * 20141-1 1-2 1-3 1-4 WEEK_OF_YEAR 1; <br> * 201412-28 12-29 12-30 12-31 WEEK_OF_YEAR 1 * </p> * * <pre> * * Example 1: * 2014-06-03 * return 23 * * Example 2: * 2014-01-01 * return 1 * * Example 3: * 2014-12-29 * return 23 * * Example 4: * 2014-12-20 * return 51 * * Example 5: * 2014-12-26 * return 52 * </pre> * * {@link Calendar#setMinimalDaysInFirstWeek(int)} ???,7? * * <pre> * * Example 1: * 2014-01-01 * return 52 * * Example 3: * 2014-12-31 * return 52 * </pre> * * ?,11??,?7,11? * * @param date * the date * @return ? * @see CalendarUtil#getFieldValue(Date, int) * @see Calendar#WEEK_OF_YEAR * @see Calendar#getFirstDayOfWeek() * @see Calendar#getMinimalDaysInFirstWeek() * @see Calendar#setMinimalDaysInFirstWeek(int) * @since 1.0.7 */ public static int getWeekOfYear(Date date) { return CalendarUtil.getFieldValue(date, Calendar.WEEK_OF_YEAR); }
From source file:com.markuspage.android.atimetracker.Tasks.java
private void switchView(int which) { Calendar tw = Calendar.getInstance(); int startDay = preferences.getInt(START_DAY, 0) + 1; tw.setFirstDayOfWeek(startDay);//from w ww .ja v a 2s . c om String ttl = getString(R.string.title, getResources().getStringArray(R.array.views)[which]); switch (which) { case 0: // today adapter.loadTasks(tw); break; case 1: // this week adapter.loadTasks(weekStart(tw, startDay), weekEnd(tw, startDay)); break; case 2: // yesterday tw.add(Calendar.DAY_OF_MONTH, -1); adapter.loadTasks(tw); break; case 3: // last week tw.add(Calendar.WEEK_OF_YEAR, -1); adapter.loadTasks(weekStart(tw, startDay), weekEnd(tw, startDay)); break; case 4: // all adapter.loadTasks(); break; case 5: // select range Calendar start = Calendar.getInstance(); start.setTimeInMillis(preferences.getLong(START_DATE, 0)); System.err.println("START = " + start.getTime()); Calendar end = Calendar.getInstance(); end.setTimeInMillis(preferences.getLong(END_DATE, 0)); System.err.println("END = " + end.getTime()); adapter.loadTasks(start, end); DateFormat f = DateFormat.getDateInstance(DateFormat.SHORT); ttl = getString(R.string.title, f.format(start.getTime()) + " - " + f.format(end.getTime())); break; default: // Unknown break; } baseTitle = ttl; setTitle(); getListView().invalidate(); }
From source file:com.frey.repo.DateUtil.java
public static int getWeekNumOfYearDay(Date curDate) { if (curDate == null) return 0; Calendar calendar = Calendar.getInstance(); calendar.setTime(curDate);//from w ww .j a v a2 s .c om int iWeekNum; if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR) - 1; } else { iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR); } // int iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR); return iWeekNum; }
From source file:com.bt.heliniumstudentapp.MainActivity.java
protected static void recoverError(final int view, final int error, final int direction, final int transition) { String postfixError = ""; switch (view) { case HeliniumStudentApp.VIEW_LOGIN: postfixError = mainContext.getResources().getString(R.string.while_login); break;//from w w w .j a va2 s. c o m case HeliniumStudentApp.VIEW_SCHEDULE: postfixError = mainContext.getResources().getString(R.string.while_schedule); break; case HeliniumStudentApp.VIEW_GRADES: postfixError = mainContext.getResources().getString(R.string.while_grades); break; } switch (error) { case HeliniumStudentApp.ERR_IO: Toast.makeText(mainContext, mainContext.getResources().getString(R.string.error_conn) + " " + postfixError, Toast.LENGTH_SHORT).show(); break; case HeliniumStudentApp.ERR_OK: Toast.makeText(mainContext, mainContext.getResources().getString(R.string.error_ok) + " " + postfixError, Toast.LENGTH_SHORT).show(); break; case HeliniumStudentApp.ERR_UNDEFINED: Toast.makeText(mainContext, mainContext.getResources().getString(R.string.error) + " " + postfixError, Toast.LENGTH_SHORT).show(); break; case HeliniumStudentApp.ERR_USERPASS: Toast.makeText(mainContext, mainContext.getResources().getString(R.string.error_userpass), Toast.LENGTH_SHORT).show(); break; } switch (view) { case HeliniumStudentApp.VIEW_LOGIN: LoginActivity.authenticationProgressDialog.cancel(); if (error == HeliniumStudentApp.ERR_USERPASS) PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putString("password", null) .apply(); break; case HeliniumStudentApp.VIEW_SCHEDULE: final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); switch (transition) { case HeliniumStudentApp.ACTION_INIT_OUT: case HeliniumStudentApp.ACTION_SHORT_OUT: if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null) == null) { //TODO Does this ever happen or is this handled by checkDatabase? Toast.makeText(mainContext, mainContext.getResources().getString(R.string.database_no), Toast.LENGTH_SHORT).show(); mainContext.finish(); //FIXME Properly close, otherwise app will become really glitchy... } else { setStatusBar(mainContext); ScheduleFragment.scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); ScheduleFragment.parseData(transition); } break; } switch (direction) { case HeliniumStudentApp.DIREC_BACK: if (ScheduleFragment.scheduleFocus > currentWeek && PreferenceManager .getDefaultSharedPreferences(mainContext).getString("schedule_1", null) != null) { ScheduleFragment.scheduleFocus = currentWeek + 1; ScheduleFragment.scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null); } else { ScheduleFragment.scheduleFocus = currentWeek; ScheduleFragment.scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } ScheduleFragment.parseData(transition); break; case HeliniumStudentApp.DIREC_CURRENT: setUI(view, transition); break; case HeliniumStudentApp.DIREC_NEXT: if (ScheduleFragment.scheduleFocus > currentWeek && PreferenceManager .getDefaultSharedPreferences(mainContext).getString("schedule_1", null) != null) { ScheduleFragment.scheduleFocus = currentWeek + 1; ScheduleFragment.scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null); } else { ScheduleFragment.scheduleFocus = currentWeek; ScheduleFragment.scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } ScheduleFragment.parseData(transition); break; case HeliniumStudentApp.DIREC_OTHER: ScheduleFragment.scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR); ScheduleFragment.scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); ScheduleFragment.parseData(transition); break; } break; case HeliniumStudentApp.VIEW_GRADES: if (direction >= HeliniumStudentApp.FOCUS_YEAR) { GradesFragment.yearFocus = direction - HeliniumStudentApp.FOCUS_YEAR; } else { switch (direction) { case HeliniumStudentApp.DIREC_BACK: GradesFragment.termFocus++; break; case HeliniumStudentApp.DIREC_NEXT: GradesFragment.termFocus--; break; } } switch (transition) { case HeliniumStudentApp.ACTION_INIT_OUT: if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) == null) { //TODO Keep and display empty GradesFragment with retry option Toast.makeText(mainContext, mainContext.getResources().getString(R.string.database_no), Toast.LENGTH_SHORT).show(); drawerNV.getMenu().findItem(R.id.i_schedule_md).setChecked(true); FM.beginTransaction().replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE") .commit(); setUI(view, transition); } else { GradesFragment.gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("html_grades", null); //TODO Move elsewhere like in ScheduleFragment GradesFragment.parseData(transition); } break; case HeliniumStudentApp.ACTION_REFRESH_OUT: setUI(view, transition); break; } break; } }
From source file:com.alkacon.opencms.calendar.CmsCalendarDisplay.java
/** * Returns the calendar entries of the collected resources that match the actual * time period.<p>// w w w. j a v a2 s . co m * * @param type the type of time period * @return all entries for the days of the specified range with their corresponding entries as lists */ public Map getEntriesForCurrentPeriod(int type) { Calendar current = getCurrentDate(); switch (type) { case PERIOD_DAY: return getEntriesForDay(current.get(Calendar.YEAR), current.get(Calendar.DAY_OF_YEAR)); case PERIOD_WEEK: return getEntriesForWeek(current.get(Calendar.YEAR), current.get(Calendar.WEEK_OF_YEAR)); case PERIOD_MONTH: return getEntriesForMonth(current.get(Calendar.YEAR), current.get(Calendar.MONTH)); case PERIOD_YEAR: return getEntriesForYear(current.get(Calendar.YEAR)); default: return new TreeMap(); } }
From source file:com.ecarinfo.weichexin.httpserver.module.CarManager.java
private List<ECCarInfoItemVO> weekList(List<ECCarInfoItemVO> list) { Calendar nowDate = Calendar.getInstance(); Calendar canlendar = Calendar.getInstance(); List<ECCarInfoItemVO> voList = new ArrayList<ECCarInfoItemVO>(); try {/*w w w . j a va 2 s . c om*/ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); nowDate.setTime(format.parse(format.format(new Date()))); nowDate.add(Calendar.WEEK_OF_YEAR, -1); String s = format.format(nowDate.getTime()); //?1 nowDate.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);// int lastday = nowDate.get(Calendar.DAY_OF_MONTH);// nowDate.add(Calendar.DAY_OF_YEAR, -1); if (list != null && list.size() > 0) { for (int i = 0; i < 7; i++) { boolean flag = true; nowDate.add(Calendar.DAY_OF_YEAR, 1); for (int k = 0; k < list.size(); k++) { if (list.get(k).getFromDay() != null) { canlendar.setTime(list.get(k).getFromDay()); if (nowDate.getTimeInMillis() == canlendar.getTimeInMillis()) {//?vo?? voList.add(list.get(k)); flag = false; break; } } } if (flag) { ECCarInfoItemVO vo = new ECCarInfoItemVO(); vo.setFromDay(format.parse(format.format(nowDate.getTime()))); vo.setTotalOil(0f); vo.setTotalMileage(0f); voList.add(vo); BeanUtils.toString(vo); } } } else {//?0 for (int i = 1; i <= 7; i++) { nowDate.add(Calendar.DAY_OF_YEAR, 1); format.format(nowDate.getTime()); ECCarInfoItemVO vo = new ECCarInfoItemVO(); vo.setFromDay(format.parse(format.format(nowDate.getTime()))); vo.setTotalOil(0f); vo.setTotalMileage(0f); voList.add(vo); BeanUtils.toString(vo); } } } catch (Exception e) { logger.error("??", e); } return voList; }
From source file:com.commander4j.util.JUtility.java
/** * Method getWeekOfYear.//from w ww . java 2 s.c o m * * @param currentDate * Calendar * @return int */ public static String getWeekOfYear(Calendar currentDate) { int temp = 0; String result = ""; temp = currentDate.get(Calendar.WEEK_OF_YEAR); result = String.valueOf(temp).trim(); result = padString(result, false, 2, "0"); return result; }
From source file:org.openmrs.module.formentry.FormEntryUtil.java
/** * Replaces %Y in the string with the four digit year. Replaces %M with the two digit month * Replaces %D with the two digit day Replaces %w with week of the year Replaces %W with week of * the month//from w w w .j a va2 s.c o m * * @param str String filename containing variables to replace with date strings * @return String with variables replaced */ public static String replaceVariables(String str, Date d) { Calendar calendar = Calendar.getInstance(); if (d != null) calendar.setTime(d); int year = calendar.get(Calendar.YEAR); str = str.replace("%Y", Integer.toString(year)); int month = calendar.get(Calendar.MONTH) + 1; String monthString = Integer.toString(month); if (month < 10) monthString = "0" + monthString; str = str.replace("%M", monthString); int day = calendar.get(Calendar.DATE); String dayString = Integer.toString(day); if (day < 10) dayString = "0" + dayString; str = str.replace("%D", dayString); int week = calendar.get(Calendar.WEEK_OF_YEAR); String weekString = Integer.toString(week); if (week < 10) weekString = "0" + week; str = str.replace("%w", weekString); int weekmonth = calendar.get(Calendar.WEEK_OF_MONTH); String weekmonthString = Integer.toString(weekmonth); if (weekmonth < 10) weekmonthString = "0" + weekmonthString; str = str.replace("%W", weekmonthString); return str; }