日期时间段
public ActionForward doSelectSect(
ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
ActionForward forward = null;
try {
int seletType = 0;
//查询时间
ReportForm form = (ReportForm) actionForm;
if (form.getTimesect() != null) {
seletType = Integer.parseInt(form.getTimesect());
}
Calendar thisMonth = Calendar.getInstance();
Date d = new Date();
String month = ReoprtUtils.getMonth(d);
String year = ReoprtUtils.getYear(d);
thisMonth.set(Calendar.MONTH, Integer.parseInt(month) - 1);
thisMonth.set(Calendar.YEAR, Integer.parseInt(year));
thisMonth.setFirstDayOfWeek(Calendar.SUNDAY);
thisMonth.set(Calendar.DAY_OF_MONTH, 1);
//本月最大天数
int maxIndex = thisMonth.getActualMaximum(Calendar.DAY_OF_MONTH);
switch (seletType) {
case 1: //当天
form.setBtime(ReoprtUtils.getFormatDate(new Date(), 3));
form.setEtime(ReoprtUtils.getFormatDate(new Date(), 3));
break;
case 2: //本月
form.setBtime(year + "-" + month + "-" + "01");
if (maxIndex < 10) {
form.setEtime(year + "-" + month + "-" + "0" + maxIndex);
} else {
form.setEtime(year + "-" + month + "-" + maxIndex);
}
break;
case 3: //本年
form.setBtime(year + "-01-01");
form.setEtime(year + "-12-31");
break;
case 4: //上月
Calendar pastM = Calendar.getInstance();
Date td = new Date();
String month1 = ReoprtUtils.getMonth(td);
String year1 = ReoprtUtils.getYear(td);
int mTemp = Integer.parseInt(month1) - 2;
if (mTemp < 0) {
month1 = "12";
year1 = String.valueOf(Integer.parseInt(year1) - 1);
}
int mTemp2 = Integer.parseInt(month1) - 1;
String sTemp2 = "";
if (mTemp2 < 10) {
sTemp2 = "0" + String.valueOf(mTemp2);
} else {
sTemp2 = String.valueOf(mTemp2);
}
pastM.set(Calendar.MONTH, mTemp);
pastM.set(Calendar.YEAR, Integer.parseInt(year1));
pastM.setFirstDayOfWeek(Calendar.SUNDAY);
pastM.set(Calendar.DAY_OF_MONTH, 1);
//上月最大天数
int max = pastM.getActualMaximum(Calendar.DAY_OF_MONTH);
form.setBtime(year1 + "-" + sTemp2 + "-" + "01");
if (maxIndex < 10) {
form.setEtime(year1 + "-" + sTemp2 + "-" + "0" + max);
} else {
form.setEtime(year1 + "-" + sTemp2 + "-" + max);
}
break;
case 5: //去年
int leastYear = Integer.parseInt(ReoprtUtils.getYear(new Date())) - 1;
form.setBtime(String.valueOf(leastYear) + "-01-01");
form.setEtime(String.valueOf(leastYear) + "-12-31");
break;
case 6: //全部
form.setBtime("1900-01-01");
form.setEtime("2100-12-31");
break;
}
request.setAttribute("form", form);
forward = mapping.findForward("reportDetail");
} catch (Exception e) {
forward = mapping.findForward("error");
}
return forward;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
