我个人认为在jsp页面来进行转换和判断很麻烦,所以呢,我在传到jsp页面之前就在action里面写了这个方法来进行处理。个人测试了一下,暂时还没发现异常。@SuppressWarnings("all")
private static String calendar(String date,int month,int day){
java.util.Date dt=new java.util.Date(date);
Calendar cal=Calendar.getInstance();
cal.setTime(dt);
if(month!=0){
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+month, cal.get(Calendar.DAY_OF_MONTH));
}
if(day!=0){
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), (cal.get(Calendar.DAY_OF_MONTH)+day));
}
String year,mon,dy;
year=cal.get(Calendar.YEAR)+"";
mon=(cal.get(Calendar.MONTH)+1)<10?"0"+(cal.get(Calendar.MONTH)+1):(cal.get(Calendar.MONTH)+1)+"";
dy=cal.get(Calendar.DAY_OF_MONTH)+"";

return year+"/"+mon+"/"+dy;

}