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

The following examples show how to use org.apache.commons.lang3.time.DateUtils#setYears() . 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: 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 2
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 3
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 4
Source File: DateUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 设置年份, 公元纪年.
 */
public static Date setYears(@NotNull final Date date, int amount) {
	return DateUtils.setYears(date, amount);
}
 
Example 5
Source File: DateUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 设置年份, 公元纪年.
 */
public static Date setYears(@NotNull final Date date, int amount) {
	return DateUtils.setYears(date, amount);
}
 
Example 6
Source File: DateUtil.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
/**
 * 设置年份, 公元纪年.
 */
public static Date setYears(@NotNull final Date date, int amount) {
	return DateUtils.setYears(date, amount);
}
 
Example 7
Source File: ProfileUtils.java    From sakai with Educational Community License v2.0 2 votes vote down vote up
/**
 * Strip the year from a given date (actually just sets it to 1)
 * 
 * @param date	original date
 * @return
 */
public static Date stripYear(Date date){
	return DateUtils.setYears(date, 1);
}
 
Example 8
Source File: ProfileUtils.java    From sakai with Educational Community License v2.0 2 votes vote down vote up
/**
 * Strip the year from a given date (actually just sets it to 1)
 * 
 * @param date	original date
 * @return
 */
public static Date stripYear(Date date){
	return DateUtils.setYears(date, 1);
}