获取当前时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
System.out.println("当前时间:" + sdf.format(now));
获取当前时间往前推n分钟的方法
Calendar beforeTime = Calendar.getInstance();
beforeTime.add(Calendar.MINUTE, -n);
beforeD = beforeTime.getTime();
System.out.println("往后推"+n+"分钟时间:"+sdf.format(beforeD) );
获取当前时间几个月前时间
Calendar beforeTime = Calendar.getInstance();
beforeTime.add(Calendar.MONTH, -2);
Date beforeD = beforeTime.getTime();
System.out.println("往前推3个月时间:"+sdf.format(beforeD) );