/**
* 根据当前时间获取本周周一日期
* @return
*/
public static String getOneWeeks(){
Calendar cal =Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); //获取本周一的日期
return df.format(cal.getTime());
}
/**
* 日期增加天数
* @param date1
* @return
* @throws Exception
*/
public static String addDays(String date,int Days) {
if(date==null||date.length()!=8){
return null;
}
Calendar calendar = Calendar.getInstance() ; //= new Calendar(2011,9,13);
calendar.set(Integer.parseInt(date.substring(0,4)),
Integer.parseInt(date.substring(4,6))-1,
Integer.parseInt(date.substring(6,8)));//指定一个日期
calendar.add(Calendar.DATE, Days);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return sdf.format(calendar.getTime());
}
public static void main(String[] args) throws ParseException {
//江湖动态日期
String travelDate = "";
String travelBeginDate = "";
String travelEndDate = "";
travelBeginDate = DateUtils.getOneWeeks();
travelEndDate = DateUtil.addDays(travelBeginDate, 4);
travelDate = DateUtils.convertDateTime3(travelBeginDate) + "-" +DateUtils.convertDateTime3(travelEndDate);
System.out.println("travelBeginDate="+travelBeginDate);
System.out.println("travelEndDate="+travelEndDate);
System.out.println("travelDate="+travelDate);
}