Date toDate = new Date(114, 5, 30);
Calendar calendar = Calendar.getInstance();
Calendar calendarTo = Calendar.getInstance();
calendar.setTime(toDate);
calendarTo.setTime(toDate);
calendarTo.add(Calendar.DATE, 1);
这是我初始化日历的方式,我试图将NEXT日放在calendarTo中 但是当我得到calendar.Date时它等于calendarTo.DATE并且等于5 ..为什么? 我怎么能最终增加这个DATE值?
答案 0 :(得分:1)
您获得的是Calendar类中DATE的默认值。这是5
public final static int DATE = 5;
但是当我从你的代码中打印日期时,看起来很好。
Date toDate = new Date(114, 5, 30);
Calendar calendar = Calendar.getInstance();
Calendar calendarTo = Calendar.getInstance();
calendar.setTime(toDate);
calendarTo.setTime(toDate);
calendarTo.add(Calendar.DATE, 1);
System.out.println(toDate);//Mon Jun 30 00:00:00 IST 2014
System.out.println(calendarTo.getTime());//Tue Jul 01 00:00:00 IST 2014