本文整理匯總了Java中org.apache.commons.lang.time.DateUtils.addYears方法的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils.addYears方法的具體用法?Java DateUtils.addYears怎麽用?Java DateUtils.addYears使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.time.DateUtils
的用法示例。
在下文中一共展示了DateUtils.addYears方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: clearLog
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(int jobGroup, int jobId, int type){
Date clearBeforeTime = null;
int clearBeforeNum = 0;
if (type == 1) {
clearBeforeTime = DateUtils.addMonths(new Date(), -1); // 清理一個月之前日誌數據
} else if (type == 2) {
clearBeforeTime = DateUtils.addMonths(new Date(), -3); // 清理三個月之前日誌數據
} else if (type == 3) {
clearBeforeTime = DateUtils.addMonths(new Date(), -6); // 清理六個月之前日誌數據
} else if (type == 4) {
clearBeforeTime = DateUtils.addYears(new Date(), -1); // 清理一年之前日誌數據
} else if (type == 5) {
clearBeforeNum = 1000; // 清理一千條以前日誌數據
} else if (type == 6) {
clearBeforeNum = 10000; // 清理一萬條以前日誌數據
} else if (type == 7) {
clearBeforeNum = 30000; // 清理三萬條以前日誌數據
} else if (type == 8) {
clearBeforeNum = 100000; // 清理十萬條以前日誌數據
} else if (type == 9) {
clearBeforeNum = 0; // 清理所有日誌數據
} else {
return new ReturnT<String>(ReturnT.FAIL_CODE, "清理類型參數異常");
}
xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
return ReturnT.SUCCESS;
}
示例2: clearLog
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(int jobGroup, int jobId, int type){
Date clearBeforeTime = null;
int clearBeforeNum = 0;
if (type == 1) {
clearBeforeTime = DateUtils.addMonths(new Date(), -1); // 清理一個月之前日誌數據
} else if (type == 2) {
clearBeforeTime = DateUtils.addMonths(new Date(), -3); // 清理三個月之前日誌數據
} else if (type == 3) {
clearBeforeTime = DateUtils.addMonths(new Date(), -6); // 清理六個月之前日誌數據
} else if (type == 4) {
clearBeforeTime = DateUtils.addYears(new Date(), -1); // 清理一年之前日誌數據
} else if (type == 5) {
clearBeforeNum = 1000; // 清理一千條以前日誌數據
} else if (type == 6) {
clearBeforeNum = 10000; // 清理一萬條以前日誌數據
} else if (type == 7) {
clearBeforeNum = 30000; // 清理三萬條以前日誌數據
} else if (type == 8) {
clearBeforeNum = 100000; // 清理十萬條以前日誌數據
} else if (type == 9) {
clearBeforeNum = 0; // 清理所用日誌數據
} else {
return new ReturnT<String>(ReturnT.FAIL_CODE, "清理類型參數異常");
}
xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
return ReturnT.SUCCESS;
}
示例3: testTemporalType
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Test
public void testTemporalType() throws Exception {
Date nextYear = DateUtils.addYears(AppBeans.get(TimeSource.class).currentTimestamp(), 1);
LoadContext<User> loadContext = LoadContext.create(User.class).setQuery(
LoadContext.createQuery("select u from sec$User u where u.createTs = :ts")
.setParameter("ts", nextYear, TemporalType.DATE));
List<User> users = dataManager.loadList(loadContext);
assertTrue(users.isEmpty());
}
示例4: addYears
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 給指定日期加幾年
*
* @param date
* 指定的日期
* @param numYears
* 需要往後加的年數
* @return 加好後的日期
*/
public static Date addYears(Date date, int numYears) {
Assert.notNull(date);
return DateUtils.addYears(date, numYears);
}