java关于当前时间分别累加相应的年、月、日
SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c = Calendar.getInstance();
//累加七天 c.setTime(new Date()); c.add(Calendar.DATE, 7); Date d = c.getTime(); String day = df.format(d); //累加三个月 c.setTime(new Date()); c.add(Calendar.MONTH, 3); Date m3 = c.getTime(); String mon3 = df.format(m3); //累加一年 c.setTime(new Date()); c.add(Calendar.YEAR, 1); Date y = c.getTime(); String year = df.format(y); System.out.println("过去一年:"+year);如果想看当前时间往前推时间将添加的数改为负数即可
如果你不知道自己要去哪里,那么去哪里都是一样

浙公网安备 33010602011771号