Java Code Examples for org.apache.commons.lang3.time.DateUtils#addWeeks()
The following examples show how to use
org.apache.commons.lang3.time.DateUtils#addWeeks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalendarScreen.java From sample-timesheets with Apache License 2.0 | 5 votes |
protected FactAndPlan[] calculateSummariesByWeeks() { Date start = firstDayOfMonth; java.util.Calendar javaCalendar = java.util.Calendar.getInstance(userSession.getLocale()); javaCalendar.setMinimalDaysInFirstWeek(1); javaCalendar.setTime(firstDayOfMonth); int countOfWeeksInTheMonth = javaCalendar.getActualMaximum(java.util.Calendar.WEEK_OF_MONTH); Date lastDayOfMonth = DateUtils.addHours(DateTimeUtils.getLastDayOfMonth(firstDayOfMonth), 23); FactAndPlan[] summariesByWeeks = new FactAndPlan[countOfWeeksInTheMonth + 1]; for (int i = 0; i < countOfWeeksInTheMonth; i++) { Date firstDayOfWeek = DateTimeUtils.getFirstDayOfWeek(start); Date lastDayOfWeek = DateUtils.addHours(DateTimeUtils.getLastDayOfWeek(start), 23); if (firstDayOfWeek.getTime() < firstDayOfMonth.getTime()) { firstDayOfWeek = firstDayOfMonth; } if (lastDayOfWeek.getTime() > lastDayOfMonth.getTime()) { lastDayOfWeek = lastDayOfMonth; } FactAndPlan summaryForTheWeek = new FactAndPlan(); User currentOrSubstitutedUser = userSession.getCurrentOrSubstitutedUser(); summaryForTheWeek.fact.setTime( validationTools.actualWorkHoursForPeriod(firstDayOfWeek, lastDayOfWeek, currentOrSubstitutedUser) ); summaryForTheWeek.plan.setTime( validationTools.workHoursForPeriod(firstDayOfWeek, lastDayOfWeek, currentOrSubstitutedUser) ); summariesByWeeks[i + 1] = summaryForTheWeek; start = DateUtils.addWeeks(start, 1); } return summariesByWeeks; }
Example 2
Source File: DateUtil.java From vjtools with Apache License 2.0 | 4 votes |
/** * 加一周 */ public static Date addWeeks(@NotNull final Date date, int amount) { return DateUtils.addWeeks(date, amount); }
Example 3
Source File: DateUtil.java From vjtools with Apache License 2.0 | 4 votes |
/** * 减一周 */ public static Date subWeeks(@NotNull final Date date, int amount) { return DateUtils.addWeeks(date, -amount); }
Example 4
Source File: DateUtil.java From vjtools with Apache License 2.0 | 4 votes |
/** * 加一周 */ public static Date addWeeks(@NotNull final Date date, int amount) { return DateUtils.addWeeks(date, amount); }
Example 5
Source File: DateUtil.java From vjtools with Apache License 2.0 | 4 votes |
/** * 减一周 */ public static Date subWeeks(@NotNull final Date date, int amount) { return DateUtils.addWeeks(date, -amount); }
Example 6
Source File: DateUtil.java From j360-dubbo-app-all with Apache License 2.0 | 4 votes |
/** * 加一周 */ public static Date addWeeks(@NotNull final Date date, int amount) { return DateUtils.addWeeks(date, amount); }
Example 7
Source File: DateUtil.java From j360-dubbo-app-all with Apache License 2.0 | 4 votes |
/** * 减一周 */ public static Date subWeeks(@NotNull final Date date, int amount) { return DateUtils.addWeeks(date, -amount); }
Example 8
Source File: DatePlusWeeks.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void add_weeks_to_date_in_java_with_apachecommons () { Calendar xmas = Calendar.getInstance(); xmas.set(2012, 11, 25, 0, 0, 0); Date newYearsDay = DateUtils.addWeeks(xmas.getTime(), 1); SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z"); logger.info(dateFormatter.format(xmas.getTime())); logger.info(dateFormatter.format(newYearsDay)); assertTrue(newYearsDay.after(xmas.getTime())); }
Example 9
Source File: DateMinusWeeks.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void subtract_weeks_from_date_in_java_apachecommons () { Calendar newYearsDay = Calendar.getInstance(); newYearsDay.set(2013, 0, 1, 0, 0, 0); Date xmas = DateUtils.addWeeks(newYearsDay.getTime(), -1); SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z"); logger.info(dateFormatter.format(newYearsDay.getTime())); logger.info(dateFormatter.format(xmas)); assertTrue(xmas.before(newYearsDay.getTime())); }
Example 10
Source File: DateUtil.java From feilong-core with Apache License 2.0 | 2 votes |
/** * 指定日期 <code>date</code>加减星期 . * * <h3>说明:</h3> * <blockquote> * <ol> * <li>结果会自动跨月,跨年计算.</li> * <li>传入的参数 <code>date</code> 不会改变</li> * </ol> * </blockquote> * * <h3>示例:</h3> * * <blockquote> * * <pre class="code"> * DateUtil.addWeek(2012-06-29 00:45:18,5) =2012-08-03 00:45:18 * DateUtil.addWeek(2012-06-29 00:45:18,-5) =2012-05-25 00:45:18 * </pre> * * </blockquote> * * @param date * 任意时间 * @param week * 需要加减的星期数,<span style="color:red">可以是负数</span>,表示前面多少<br> * @return 如果 <code>date</code>是null,抛出 {@link java.lang.IllegalArgumentException}<br> * 如果 <code>week==0</code>,那么什么都不做,返回 <code>date</code>,参见 {@link GregorianCalendar#add(int, int)} * @throws IllegalArgumentException * 如果 <code>date</code> 是<code>null</code> * @see org.apache.commons.lang3.time.DateUtils#addWeeks(Date, int) */ public static Date addWeek(Date date,int week){ return DateUtils.addWeeks(date, week); }