- Date → Calendar
public Calendar date2Calendar(Date date){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
}
或者
public static void main(String args[]){
Date date=new Date();
Calendar cal=Calendar.getInstance();
cal.setTime(date);
System.out.println(cal.get(Calendar.YEAR));
}
- Calendar → Date
public Date calendar2Date(Calendar calendar){
return calendar.getTime();
}
或者
(1) Calendar转化为Date()
Calendar cal=Calendar.getInstance();
Date() date=cal.getTime();
(2) Date转化为Calendar
Date date=new Date();
Calendar cal=Calendar.getInstance();
cal.setTime(date);
- 减一个月
Calendar calETime = Calendar.getInstance();
calETime.setTime(customer.getRefundStime());
calETime.add(Calendar.MONTH,-1);
String belongSTime = yearFormat.format(calETime.getTime());
invoiceRemind.setExpensesBelong(belongSTime+"-"+belongETime);
- 减三个月
Calendar calETime = Calendar.getInstance();
calETime.setTime(customer.getRefundStime());
calETime.add(Calendar.MONTH,-3);
|