获取以当前日期为结束日期的一周内的时间:
String paramStartDate = "";
String paramEndDate = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dateNow = new Date();
Date dateBefore = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(dateNow);
cal.add(Calendar.DAY_OF_MONTH, -6);
dateBefore = cal.getTime();
paramEndDate = sdf.format(dateNow);
paramStartDate = sdf.format(dateBefore);
获取以当前日期为结束日期一个月内的时间:
String paramStartDate = "";
String paramEndDate = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dateNow = new Date();
Date dateBefore = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(dateNow);
cal.add(Calendar.MONTH, -1);
dateBefore = cal.getTime();
paramEndDate = sdf.format(dateNow);
paramStartDate = sdf.format(dateBefore);
获取以当前日期为结束日期当年的时间:
String paramStartDate = "";
String paramEndDate = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dateNow = new Date();
Date dateBefore = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(dateNow);
cal.set(cal.get(Calendar.YEAR) - 1, 12, 1);
dateBefore = cal.getTime();
paramStartDate = sdf.format(dateBefore);
获取两个日期之间的相差天数:
spaceDay = (int) ((sdf.parse(paramEndDate).getTime() - sdf.parse(paramStartDate).getTime())
/ (1000 * 60 * 60 * 24));