日期:2014-05-18  浏览次数:20763 次

关于日期加一天
java.util.Date   date=new   date();//取时间

    Calendar   calendar   =   new   GregorianCalendar();

          calendar.setTime(date);

    calendar.add(calendar.DATE,1);//把日期往后增加一天.整数往后推,负数往前移动

          date=calendar.getTime();   //这个时间就是日期往后推一天的结果
我用了上面这个类   可是好像只能对当前的时间操作
我想要的是对输入的任意一个时间加一天的类   请各位大哥帮帮忙



------解决方案--------------------
GregorianCalendar worldTour = new GregorianCalendar(yearOfInt,monthOfInt,dayOfInt);
然后yearOfInt就是年的整数值,monthOfInt,dayOfInt分别是月和日
------解决方案--------------------
跟我的问题差不多
------解决方案--------------------
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd ");
Date date=sdf.parse(inputDate);
return date.setDate(date.getDate()+1);
------解决方案--------------------
Date d=new Date();
Calendar c=Calendar.getInstance();
c.setTime(d);
c.add(Calendar.DAY_OF_MONTH, 1);

------解决方案--------------------
Calendar calendar = new GregorianCalendar(yearOfInt,monthOfInt,dayOfInt)
calendar.add(calendar.DATE,1);

yearOfInt,monthOfInt,dayOfInt三个参数就是你自己输入的年月日~~
------解决方案--------------------
注意
Parameters:
year
the year of the date

month
the month of the date. This value is 0-based; for example, 0 for January

day
the day of the month

hour
the hour (between 0 and 23)

minutes
the minutes (between 0 and 59)

seconds
the seconds (between 0 and 59)


// construct d as current date
GregorianCalendar d = new GregorianCalendar();
d.set(1999, 11, 15);
d.add(Calendar.DAY_OF_MONTH, 1);
------解决方案--------------------
//得到给定时间的前一天
public static Timestamp getTimePriviousDay(Timestamp date){
long time = date.getTime();
time = time - 24*60*60*1000;
return new Timestamp(time);
}


/**
* 得到给定日期的前n天
* @param String date YYYY-MM-DD
* @return String dateYYYY-MM-DD
* @author lxb 2007-1-31
*/
public static String getTimePriTenDay(String date,int n){
java.util.Date temDate = ToolsUtil.getTimeStringToDate(date);
SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd ");
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(temDate);
gc.add(5,-n);
gc.set(gc.get(gc.YEAR),gc.get(gc.MONTH),gc.get(gc.DATE));
return df.format(gc.getTime());
}