public class afterTime {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("当前时间"+df.format(new Date()));
Date date = stepMonth(new Date(), -1);
System.out.println("前一个月时间为"+df.format(date));
}
public static Date stepMonth(Date sourceDate, int month) {
Calendar c = Calendar.getInstance();
c.setTime(sourceDate);
c.add(Calendar.MONTH, month);
return c.getTime();
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-21941.html