java中的时间运算的方法有多种,我觉得最好用的是这一种:
Date now2 = new Date();//获取当前时间
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(now2);//将当前时间设置进去
根据需要去加减时间
rightNow.add(Calendar.MONTH,-1);//日期减去1个月
rightNow.add(Calendar.DAY,-1);//日期减去1天
Date now2Result=rightNow.getTime();//最后的时间
格式化一下
SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String resultDate6=sdf2.format(now2Result);
ok。输出resultDate6就是你要的时间了