Java Code Examples for org.apache.commons.lang3.time.DateUtils#setDays()

The following examples show how to use org.apache.commons.lang3.time.DateUtils#setDays() . 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: WxMaAnalysisServiceImplTest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMonthlyVisitTrend() throws Exception {
  Date now = new Date();
  Date firstDayOfThisMonth = DateUtils.setDays(now, 1);
  Date lastDayOfLastMonth = DateUtils.addDays(firstDayOfThisMonth, -1);
  Date firstDayOfLastMonth = DateUtils.addMonths(firstDayOfThisMonth, -1);

  final WxMaAnalysisService service = wxMaService.getAnalysisService();
  List<WxMaVisitTrend> trends = service.getMonthlyVisitTrend(firstDayOfLastMonth, lastDayOfLastMonth);
  assertEquals(1, trends.size());
  System.out.println(trends);
}
 
Example 2
Source File: WxMaAnalysisServiceImplTest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMonthlyRetainInfo() throws Exception {
  Date now = new Date();
  Date firstDayOfThisMonth = DateUtils.setDays(now, 1);
  Date lastDayOfLastMonth = DateUtils.addDays(firstDayOfThisMonth, -1);
  Date firstDayOfLastMonth = DateUtils.addMonths(firstDayOfThisMonth, -1);

  final WxMaAnalysisService service = wxMaService.getAnalysisService();
  WxMaRetainInfo retainInfo = service.getMonthlyRetainInfo(firstDayOfLastMonth, lastDayOfLastMonth);
  assertNotNull(retainInfo);
  System.out.println(retainInfo);
}
 
Example 3
Source File: CleanUpScheduler.java    From vjtools with Apache License 2.0 5 votes vote down vote up
/**
 * return current date time by specified hour:minute
 * 
 * @param plan format: hh:mm
 */
public static Date getCurrentDateByPlan(String plan, String pattern) {
	try {
		FastDateFormat format = FastDateFormat.getInstance(pattern);
		Date end = format.parse(plan);
		Calendar today = Calendar.getInstance();
		end = DateUtils.setYears(end, (today.get(Calendar.YEAR)));
		end = DateUtils.setMonths(end, today.get(Calendar.MONTH));
		end = DateUtils.setDays(end, today.get(Calendar.DAY_OF_MONTH));
		return end;
	} catch (Exception e) {
		throw ExceptionUtil.unchecked(e);
	}
}
 
Example 4
Source File: CleanUpScheduler.java    From vjtools with Apache License 2.0 5 votes vote down vote up
/**
 * return current date time by specified hour:minute
 * 
 * @param plan format: hh:mm
 */
public static Date getCurrentDateByPlan(String plan, String pattern) {
	try {
		FastDateFormat format = FastDateFormat.getInstance(pattern);
		Date end = format.parse(plan);
		Calendar today = Calendar.getInstance();
		end = DateUtils.setYears(end, (today.get(Calendar.YEAR)));
		end = DateUtils.setMonths(end, today.get(Calendar.MONTH));
		end = DateUtils.setDays(end, today.get(Calendar.DAY_OF_MONTH));
		return end;
	} catch (Exception e) {
		throw ExceptionUtil.unchecked(e);
	}
}
 
Example 5
Source File: CleanUpScheduler.java    From feeyo-redisproxy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * return current date time by specified hour:minute
 * 
 * @param plan format: hh:mm
 */
public static Date getCurrentDateByPlan(String plan, String pattern) {
	try {
		FastDateFormat format = FastDateFormat.getInstance(pattern);
		Date end = format.parse(plan);
		Calendar today = Calendar.getInstance();
		end = DateUtils.setYears(end, (today.get(Calendar.YEAR)));
		end = DateUtils.setMonths(end, today.get(Calendar.MONTH));
		end = DateUtils.setDays(end, today.get(Calendar.DAY_OF_MONTH));
		return end;
	} catch (Exception e) {
		throw new RuntimeException( e );
	}
}
 
Example 6
Source File: DateUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 设置日期, 1-31.
 */
public static Date setDays(@NotNull final Date date, int amount) {
	return DateUtils.setDays(date, amount);
}
 
Example 7
Source File: DateUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 设置日期, 1-31.
 */
public static Date setDays(@NotNull final Date date, int amount) {
	return DateUtils.setDays(date, amount);
}
 
Example 8
Source File: DateUtil.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
/**
 * 设置日期, 1-31.
 */
public static Date setDays(@NotNull final Date date, int amount) {
	return DateUtils.setDays(date, amount);
}