本文整理匯總了Java中org.apache.commons.lang.time.DateUtils.addDays方法的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils.addDays方法的具體用法?Java DateUtils.addDays怎麽用?Java DateUtils.addDays使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.time.DateUtils
的用法示例。
在下文中一共展示了DateUtils.addDays方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTimeBetween
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
protected TimeBetween getTimeBetween(HttpServletRequest request, Model model, String startDateAtr,
String endDateAtr) throws ParseException {
String startDateParam = request.getParameter(startDateAtr);
String endDateParam = request.getParameter(endDateAtr);
Date startDate;
Date endDate;
if (StringUtils.isBlank(startDateParam) || StringUtils.isBlank(endDateParam)) {
startDate = new Date();
endDate = DateUtils.addDays(startDate, 1);
} else {
endDate = DateUtil.parseYYYY_MM_dd(endDateParam);
startDate = DateUtil.parseYYYY_MM_dd(startDateParam);
}
Date yesterDay = DateUtils.addDays(startDate, -1);
long beginTime = NumberUtils.toLong(DateUtil.formatYYYYMMddHHMM(startDate));
long endTime = NumberUtils.toLong(DateUtil.formatYYYYMMddHHMM(endDate));
model.addAttribute(startDateAtr, startDateParam);
model.addAttribute(endDateAtr, endDateParam);
model.addAttribute("yesterDay", DateUtil.formatDate(yesterDay, "yyyy-MM-dd"));
return new TimeBetween(beginTime, endTime, startDate, endDate);
}
示例2: getFromAppCommandStats
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
public static HighchartPoint getFromAppCommandStats(AppCommandStats appCommandStats, Date currentDate, int diffDays) throws ParseException {
Date collectDate = getDateTime(appCommandStats.getCollectTime());
if (!DateUtils.isSameDay(currentDate, collectDate)) {
return null;
}
//顯示用的時間
String date = null;
try {
date = DateUtil.formatDate(collectDate, "yyyy-MM-dd HH:mm");
} catch (Exception e) {
date = DateUtil.formatDate(collectDate, "yyyy-MM-dd HH");
}
// y坐標
long commandCount = appCommandStats.getCommandCount();
// x坐標
//為了顯示在一個時間範圍內
if (diffDays > 0) {
collectDate = DateUtils.addDays(collectDate, diffDays);
}
return new HighchartPoint(collectDate.getTime(), commandCount, date);
}
示例3: sendAppDailyEmail
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public int sendAppDailyEmail() {
Date endDate = new Date();
Date startDate = DateUtils.addDays(endDate, -1);
int successCount = 0;
List<AppDesc> appDescList = appService.getAllAppDesc();
for (AppDesc appDesc : appDescList) {
try {
boolean result = sendAppDailyEmail(appDesc.getAppId(), startDate, endDate);
if (result) {
successCount++;
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
return successCount;
}
示例4: appDaily
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 應用日報查詢
*/
@RequestMapping("/daily")
public ModelAndView appDaily(HttpServletRequest request,
HttpServletResponse response, Model model, Long appId) throws ParseException {
// 1. 應用信息
AppDesc appDesc = appService.getByAppId(appId);
model.addAttribute("appDesc", appDesc);
// 2. 日期
String dailyDateParam = request.getParameter("dailyDate");
Date date;
if (StringUtils.isBlank(dailyDateParam)) {
date = DateUtils.addDays(new Date(), -1);
} else {
date = DateUtil.parseYYYY_MM_dd(dailyDateParam);
}
model.addAttribute("dailyDate", dailyDateParam);
// 3. 日報
AppDailyData appDailyData = appDailyDataCenter.getAppDailyData(appId, date);
model.addAttribute("appDailyData", appDailyData);
return new ModelAndView("app/appDaily");
}
示例5: getTimesheetByEmpIdEndDate
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public Timesheet getTimesheetByEmpIdEndDate(long empId, Date timesheetEndDate) throws Exception {
logger.info("Inside getTimesheetByEndDateEmpId method of TimesheetDaoImpl---> " +
"empId: " + empId + " timesheetEndDate: " + timesheetEndDate);
Date todayDate = new Date();
List<TimesheetDetails> timesheetDetailsList = new ArrayList<>();
long timesheetDetailId = 110000;
Date weekStartDate = TimesheetDateUtils.parseDate("04/16/2017");
Date weekEndDate = DateUtils.addDays(weekStartDate, 7);
logger.info("weekStartDate: " + weekStartDate + " weekEndDate: " + weekEndDate);
SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("E"); // the day of the week abbreviated
SimpleDateFormat dayOfWeekDescFormat = new SimpleDateFormat("EEEE"); // the day of the week spelled out completely
//Check if the selected Date is before today's date
if (timesheetEndDate.before(todayDate)) {
for (int i = 1; i <= 7; ++i) {
Date weekDayDate = DateUtils.addDays(weekStartDate, 1);
logger.info("Week Day Date in the for loop: " + weekDayDate);
timesheetDetails = new TimesheetDetails(timesheetDetailId + 1, 111112, weekDayDate,
dayOfWeekFormat.format(weekDayDate), dayOfWeekDescFormat.format(weekDayDate),
8.0, 0.0, 0.0);
timesheetDetailsList.add(timesheetDetails);
}
timesheetObj = new Timesheet(999000, weekStartDate, weekEndDate, 1111001, "Timesheet for week.",
"Mahidhar", new Date(), "Mahidhar M", new Date(),
"SUBMITTED", timesheetDetailsList);
} else {
//Create an empty object and return it
timesheetObj = new Timesheet();
timesheetObj.setTimesheetDetailsList(timesheetDetailsList);
}
return timesheetObj;
}
示例6: FindAll
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public List<App> FindAll() {
String curDateString = DateFormatUtils.format(DateUtils.addDays(new Date(), config.getGenerateDate()),
"yyyy-MM-dd HH:mm:ss");
Date curDate = DateUtils.addDays(new Date(), config.getGenerateDate());
appDicts = daoDict.findAll();
screenImageList = daoScreenImage.findAll();
extendDataList = daoExtendData.findAll();
org.apache.velocity.Template templateVelocity = new VeTemplate(config.getAppGenerateTemplateBaseDir(),
"app.html").getTemplate();
Template template = new Template(config.getAppGenerateTemplateBaseDir(), "detail.html");
List<App> list;
logger.debug("run time :{}", curDateString);
if (config.getGenerateDate() == 0) {
list = dao.findAll();
} else {
list = dao.findAll(curDate);
}
for (App app : list) {
setApp(app);
// genetatePage(app);
// genetatePage(app, template);
genetatePageVelocity(app, templateVelocity);
}
return list;
}
示例7: getIncrement
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Override
public Pager<App4Summary> getIncrement(int currentPage, int pageSize, Short catalog) {
Assert.isTrue(pageSize > 0 && pageSize <= MAX_ROWS, "pageSize invalid!");
Assert.isTrue(currentPage > 0, "currentPage negative!");
// 因為在infoc 中 上報時將 type 2為應用,1為遊戲,所以為了和現有的一致,做一個轉換
if (null != catalog) {
catalog = catalog == (short) 1 ? (short) 2 : (short) 1;
}
Date date = DateUtils.addDays(new Date(), -1);
long totalCount = appMapper.getIncrementCount(catalog, date);
if (totalCount == 0) {
date = DateUtils.addDays(new Date(), -2);// 因為數據是淩晨 5點鍾導日昨天的數據,所以會出現
// 昨天數據不會出來的現象
totalCount = appMapper.getIncrementCount(catalog, date);
}
if (totalCount == 0) {
date = DateUtils.addDays(new Date(), -3);// 如果取前天的數據還是沒有,就去大後天的數據
totalCount = appMapper.getIncrementCount(catalog, date);
}
final int offset = HibernateHelper.firstResult(currentPage, pageSize);
Pager<App4Summary> pager = new Pager<App4Summary>();
pager.setRows(totalCount);
pager.setCurrentPage(currentPage);
pager.setPageSize(pageSize);
List<App4Summary> list = appMapper.getIncrement(offset, pageSize, catalog, date);
pager.setResult(list);
return pager;
}
示例8: stat
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@RequestMapping("/stat")
public ModelAndView stat(HttpServletRequest request, HttpServletResponse response, Model model, Integer admin, Long instanceId) {
String startDateParam = request.getParameter("startDate");
String endDateParam = request.getParameter("endDate");
if (StringUtils.isBlank(startDateParam) || StringUtils.isBlank(endDateParam)) {
Date endDate = new Date();
Date startDate = DateUtils.addDays(endDate, -1);
startDateParam = DateUtil.formatDate(startDate, "yyyyMMdd");
endDateParam = DateUtil.formatDate(endDate, "yyyyMMdd");
}
model.addAttribute("startDate", startDateParam);
model.addAttribute("endDate", endDateParam);
if (instanceId != null && instanceId > 0) {
model.addAttribute("instanceId", instanceId);
InstanceInfo instanceInfo = instanceStatsCenter.getInstanceInfo(instanceId);
model.addAttribute("instanceInfo", instanceInfo);
model.addAttribute("appId", instanceInfo.getAppId());
model.addAttribute("appDetail", appStatsCenter.getAppDetail(instanceInfo.getAppId()));
InstanceStats instanceStats = instanceStatsCenter.getInstanceStats(instanceId);
model.addAttribute("instanceStats", instanceStats);
List<AppCommandStats> topLimitAppCommandStatsList = appStatsCenter.getTopLimitAppCommandStatsList(instanceInfo.getAppId(), Long.parseLong(startDateParam) * 10000, Long.parseLong(endDateParam) * 10000, 5);
model.addAttribute("appCommandStats", topLimitAppCommandStatsList);
}
return new ModelAndView("instance/instanceStat");
}
示例9: validateReturnsNullForUniqueDate
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Test
public void validateReturnsNullForUniqueDate() throws Exception {
Date date1 = new Date();
Date date2 = DateUtils.addDays(new Date(), 1);
assertThat(validator.validate(0, date1, Arrays.asList(newSplit(date1), newSplit(date2)))).isNullOrEmpty();
}
示例10: updateUpdatesFirstAcquired
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Test
public void updateUpdatesFirstAcquired() throws Exception {
SecuritySummary summary = new SecuritySummary(null, 2, BigDecimal.TEN, new Date(), BigDecimal.ONE, new BigDecimal(20));
SecuritySummary summary2 = new SecuritySummary(null, 2, BigDecimal.TEN, DateUtils.addDays(new Date(), -1), BigDecimal.ONE, new BigDecimal(20));
summary.update(summary2);
assertThat(summary.getFirstAcquired()).isEqualTo(summary2.getFirstAcquired());
}
示例11: fillWithValueDistriTime
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 值分布日期格式
*/
private TimeBetween fillWithValueDistriTime(HttpServletRequest request, Model model) throws ParseException {
final String valueDistriDateFormat = "yyyy-MM-dd";
String valueDistriStartDateParam = request.getParameter("valueDistriStartDate");
String valueDistriEndDateParam = request.getParameter("valueDistriEndDate");
Date startDate;
Date endDate;
if (StringUtils.isBlank(valueDistriStartDateParam) || StringUtils.isBlank(valueDistriEndDateParam)) {
// 如果為空默認取昨天和今天
SimpleDateFormat sdf = new SimpleDateFormat(valueDistriDateFormat);
startDate = sdf.parse(sdf.format(new Date()));
endDate = DateUtils.addDays(startDate, 1);
valueDistriStartDateParam = DateUtil.formatDate(startDate, valueDistriDateFormat);
valueDistriEndDateParam = DateUtil.formatDate(endDate, valueDistriDateFormat);
} else {
endDate = DateUtil.parse(valueDistriEndDateParam, valueDistriDateFormat);
startDate = DateUtil.parse(valueDistriStartDateParam, valueDistriDateFormat);
//限製不能超過1天
if (endDate.getTime() - startDate.getTime() > TimeUnit.DAYS.toMillis(1)) {
startDate = DateUtils.addDays(endDate, -1);
}
}
// 前端需要
model.addAttribute("valueDistriStartDate", valueDistriStartDateParam);
model.addAttribute("valueDistriEndDate", valueDistriEndDateParam);
// 查詢後台需要
long startTime = NumberUtils.toLong(DateUtil.formatDate(startDate, COLLECT_TIME_FORMAT));
long endTime = NumberUtils.toLong(DateUtil.formatDate(endDate, COLLECT_TIME_FORMAT));
return new TimeBetween(startTime, endTime, startDate, endDate);
}
示例12: assembleMutilDateAppStatsJsonMinute
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 多時間組裝
* @param appStats
* @param statName
* @param startDate
* @param endDate
* @return
*/
private String assembleMutilDateAppStatsJsonMinute(List<AppStats> appStats, String statName, Date startDate, Date endDate) {
if (appStats == null || appStats.isEmpty()) {
return "[]";
}
Map<String, List<HighchartPoint>> map = new HashMap<String, List<HighchartPoint>>();
Date currentDate = DateUtils.addDays(endDate, -1);
int diffDays = 0;
while (currentDate.getTime() >= startDate.getTime()) {
List<HighchartPoint> list = new ArrayList<HighchartPoint>();
for (AppStats stat : appStats) {
try {
HighchartPoint highchartPoint = HighchartPoint.getFromAppStats(stat, statName, currentDate, diffDays);
if (highchartPoint == null) {
continue;
}
list.add(highchartPoint);
} catch (ParseException e) {
logger.info(e.getMessage(), e);
}
}
String formatDate = DateUtil.formatDate(currentDate, "yyyy-MM-dd");
map.put(formatDate, list);
currentDate = DateUtils.addDays(currentDate, -1);
diffDays++;
}
net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(map);
return jsonObject.toString();
}
示例13: generateData
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
private void generateData() {
stockChartDs.refresh();
Date startDate = DateUtils.addDays(getZeroTime(new Date()), -MINUTES_COUNT);
for (int i = 0; i < MINUTES_COUNT; i++) {
stockChartDs.includeItem(addDateValueVolumeTime(DateUtils.addMinutes(startDate, i), i));
}
}
示例14: appDaily
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@RequestMapping("/appDaily")
public ModelAndView appDaily(HttpServletRequest request, HttpServletResponse response, Model model) throws ParseException {
AppUser userInfo = getUserInfo(request);
logger.warn("user {} want to send appdaily", userInfo.getName());
if (ConstUtils.SUPER_MANAGER.contains(userInfo.getName())) {
Date startDate;
Date endDate;
String startDateParam = request.getParameter("startDate");
String endDateParam = request.getParameter("endDate");
if (StringUtils.isBlank(startDateParam) || StringUtils.isBlank(endDateParam)) {
endDate = new Date();
startDate = DateUtils.addDays(endDate, -1);
} else {
startDate = DateUtil.parseYYYY_MM_dd(startDateParam);
endDate = DateUtil.parseYYYY_MM_dd(endDateParam);
}
long appId = NumberUtils.toLong(request.getParameter("appId"));
if (appId > 0) {
appDailyDataCenter.sendAppDailyEmail(appId, startDate, endDate);
} else {
appDailyDataCenter.sendAppDailyEmail();
}
model.addAttribute("msg", "success!");
} else {
model.addAttribute("msg", "no power!");
}
return new ModelAndView("");
}
示例15: fillWithCostDateFormat
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 獲取耗時時間區間
* @throws ParseException
*/
private TimeBetween fillWithCostDateFormat(HttpServletRequest request, Model model) throws ParseException {
final String costDistriDateFormat = "yyyy-MM-dd";
String costDistriStartDateParam = request.getParameter("costDistriStartDate");
String costDistriEndDateParam = request.getParameter("costDistriEndDate");
Date startDate;
Date endDate;
if (StringUtils.isBlank(costDistriStartDateParam) || StringUtils.isBlank(costDistriEndDateParam)) {
// 如果為空默認取昨天和今天
SimpleDateFormat sdf = new SimpleDateFormat(costDistriDateFormat);
startDate = sdf.parse(sdf.format(new Date()));
endDate = DateUtils.addDays(startDate, 1);
costDistriStartDateParam = DateUtil.formatDate(startDate, costDistriDateFormat);
costDistriEndDateParam = DateUtil.formatDate(endDate, costDistriDateFormat);
} else {
endDate = DateUtil.parse(costDistriEndDateParam, costDistriDateFormat);
startDate = DateUtil.parse(costDistriStartDateParam, costDistriDateFormat);
//限製不能超過1天
if (endDate.getTime() - startDate.getTime() > TimeUnit.DAYS.toMillis(1)) {
startDate = DateUtils.addDays(endDate, -1);
}
}
// 前端需要
model.addAttribute("costDistriStartDate", costDistriStartDateParam);
model.addAttribute("costDistriEndDate", costDistriEndDateParam);
// 查詢後台需要
long startTime = NumberUtils.toLong(DateUtil.formatDate(startDate, COLLECT_TIME_FORMAT));
long endTime = NumberUtils.toLong(DateUtil.formatDate(endDate, COLLECT_TIME_FORMAT));
return new TimeBetween(startTime, endTime, startDate, endDate);
}