public static Long nextMonth(Long mon,int flag) {
Long res = 0L;
Date date = mon==null ? new Date():new Date(mon);//当前日期
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");//格式化对象
Calendar calendar = Calendar.getInstance();//日历对象
calendar.setTime(date);//设置当前日期
calendar.add(Calendar.MONTH, flag);//月份减一为-1,加一为1
res =calendar.getTime().getTime();
//System.out.println(sdf.format());//输出格式化的日期
Long res = 0L;
Date date = mon==null ? new Date():new Date(mon);//当前日期
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");//格式化对象
Calendar calendar = Calendar.getInstance();//日历对象
calendar.setTime(date);//设置当前日期
calendar.add(Calendar.MONTH, flag);//月份减一为-1,加一为1
res =calendar.getTime().getTime();
//System.out.println(sdf.format());//输出格式化的日期
return res;
}
flag:正、负数,正数表示向后加flag个月,负数表示向前减flag个月。