最近用到了日期的添加与修改,下面一起学习:
import java.util.Date ;
Date date=new Date ();//取时间
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.add(Calendar.DATE,1);//把日期往后增加一天.正数往后推,负数往前推
date=calendar.getTime(); //这个时间就是日期往后推一天的结果
Calendar.DATE
和Calendar.DAY_OF_MONTH
是一个意思,表示一个月中的一天。还有其他的表示分钟,小时等的字段
add(int field, int amount)
Adds or subtracts the specified amount of time to the given calendar field, based on the calendar’s rules.