@Test
public void DateTest() {
Date currentdate = new Date();
System.out.println("before is " + currentdate);
nextDate(currentdate);
System.out.println("after is " + currentdate);
}
/**
* 不要对 方法传递过来的对象进行赋值 , 如果想要修改对象 , 请使用return
* @param currentdate
*/
public void nextDate(Date currentdate) {
Date date = new Date();//取时间
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.add(Calendar.DATE, -1);//把日期往前减少一天,若想把日期向后推一天则将负数改为正数
date = calendar.getTime();
currentdate=date;
System.out.println(currentdate);
}
before is Thu Aug 10 11:18:46 CST 2017
Wed Aug 09 11:18:46 CST 2017
after is Thu Aug 10 11:18:46 CST 2017
网友评论