@Test
public void DateTest() {
Date currentdate = new Date();
System.out.println("before is " + currentdate);
nextDate(currentdate);
System.out.println("after is " + currentdate);
}
/**
* 不要對 方法傳遞過來的對象進(jìn)行賦值 , 如果想要修改對象 , 請使用return
* @param currentdate
*/
public void nextDate(Date currentdate) {
Date date = new Date();//取時間
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.add(Calendar.DATE, -1);//把日期往前減少一天绅作,若想把日期向后推一天則將負(fù)數(shù)改為正數(shù)
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